【问题标题】:Open a new window and get its location after loading打开一个新窗口并在加载后获取其位置
【发布时间】:2014-07-14 10:51:29
【问题描述】:

我正在使用此代码打开一个新窗口:

Window w = window.open('example2.com', 'example2'); // Consisder than my domain
                                                    // is example1.com

这部分代码工作正常并成功打开一个新窗口。比我在加载完成后尝试调用我的函数。

w.onLoad.listen(locationGetter);

这是locationGetter()函数的代码:

locationGetter(Event e) {
  Location currentLocation = w.location;
  currentHref = currentLocation.href; // currentHref is var defined
}                                    // in main() function

但是这段代码不能很好地工作。每次我运行我的脚本时,currentLocation 和 currentHref 都是空的。一开始我以为问题出在onLoad事件中,所以我尝试在打开窗口后准确调用w.location:

Window w = window.open('example2.com', 'example2');
Location currentLocation = w.location; // still null

我很确定 Window 和 WindowBase 都有 location 属性。请帮助我解决我的问题或提供此任务的替代解决方案。

【问题讨论】:

    标签: dom dart dart-html


    【解决方案1】:

    我认为这不是 Dart 问题。

    看来你遇到了这个 http://blog.carbonfive.com/2012/08/17/cross-domain-browser-window-messaging-with-html5-and-javascript/

    CORS 阻止访问其他域的窗口,您可以使用 postMessage 代替。

    【讨论】:

    • 感谢您的回答。我认为我的脚本打开的页面是脚本可交叉的,因为我能够运行 window.close()。我没有不同域的服务器,所以我会寻求不同的解决方案。
    猜你喜欢
    • 2013-09-04
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2021-04-24
    相关资源
    最近更新 更多