【问题标题】:$location.path does not work in popup browser window$location.path 在弹出的浏览器窗口中不起作用
【发布时间】:2017-03-14 06:57:11
【问题描述】:

在我的 JavaScript Addin for Excel 中,我使用 window.open("https://localhost:3000/#/posts/editor/", "popup", "width=1000, height=1100") 来弹出一个浏览器窗口。

我意识到,与普通浏览器不同,我们无法在此弹出浏览器窗口中手动修改 URL。

这个页面是angularjs建的,我在这个页面有一个保存按钮,链接到如下函数:

$scope.save = function () {
    posts.create({ title: "newCreated", link: "" })
        .success(function (post) {
            $location.path("/posts/editor/" + post._id)
        })
})

我意识到$location.path 不会在此弹出窗口中重定向页面。而在普通浏览器中,$location.path 可以工作。

有谁知道是否可以解锁弹出浏览器窗口以便$location.path 工作?

【问题讨论】:

  • 控制台有错误吗?
  • 试试 $scope.$apply()
  • 控制台@Keshav没有错误

标签: javascript angularjs google-chrome popup window


【解决方案1】:

试试$rootScope.$apply$scope.$apply()

$scope.save = function () {
    posts.create({ title: "newCreated", link: "" })
        .success(function (post) {
           $rootScope.$apply(function() {
            $location.path("/posts/editor/" + post._id)
            console.log($location.path());
          });
        })
})

【讨论】:

  • 我试过$scope.$apply(),在url栏中可以看到,新地址闪烁,然后恢复到...posts/editor/
  • $scope.$apply() 在你设置路径之后尝试这个方法之外.,,.. 你也可以使用 $state
  • 是的..更多你可以用它传递值甚至对象
  • 你可以试试window.location
  • 我意识到由于我的程序中的错误,无法在普通浏览器中加载 url "/posts/editor/" + post._id。我已经更正了它们,现在,它可以通过$location.path在普通浏览器和弹出窗口浏览器中加载。所以$location.path 可以工作,即使 url 栏不可编辑。感谢您的回答,很高兴知道$state.gowindow.location 之类的替代方案...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-20
  • 1970-01-01
相关资源
最近更新 更多