在新创建的窗口上设置 onload() ,可能吗?
我正在创建一个 Safari 扩展。在某一时刻,我想打开一个新选项卡/窗口,并在该新选项卡中的某些文本字段中输入文本。
这就是我尝试过的。
var newWindow = window.open('http://openradar.appspot.com/myradars/add', "new tab");
var fillContent = function () {
//Fill some content
//This never get called
};
newWindow.onload = fillContent;
问题是该函数永远不会被调用。
在调试过程中,我看到 newWindow
有效,但 newWindow.onload
在 newWindow.onload = fillContent 之前和之后始终未定义 ;
可以做我想做的事情吗?有更好的办法吗?
I'm creating a Safari Extension. At one point, I want to open a new tab/window and enter text on some text fields in that new tab.
This is what I tried.
var newWindow = window.open('http://openradar.appspot.com/myradars/add', "new tab");
var fillContent = function () {
//Fill some content
//This never get called
};
newWindow.onload = fillContent;
The problem is that the function never get called.
During debugging, I saw that newWindow
is valid but that newWindow.onload
is always undefined, before and after newWindow.onload = fillContent;
Is it possible to do what I'm trying to do? Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试打开的页面位于另一个域中,则这是不可能的,因为您违反了 javascript 的同源策略(该策略规定您只能“控制”与脚本运行所在的同一域中的页面)。
If the page you are trying to open is in another domain, it's impossible, because you were violating javascript's same origin policy (which states that you can only 'control' pages that are on the same domain where the script is running).