Javascript 打开一个新窗口,并调用javascript函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3772535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:05:20  来源:igfitidea点击:

open a new window, and call javascript function

javascript

提问by user455416

I am new to javascript. I would like to know how a new window can be opened from a javascript method, and then call it's javascript methods.

我是 javascript 新手。我想知道如何从 javascript 方法打开一个新窗口,然后调用它的 javascript 方法。

The url of the window, is in another domain (can cause a security problem !?), and I don't have control over it.

窗口的 url 位于另一个域中(可能导致安全问题!?),我无法控制它。

For example, a code that should behave as the followings:

例如,代码应如下所示:

handler<-openAWindow("www.someurl.com");//open a window and get a handler for it
handler->someMethod1(param1, param2);//call some javascript method 
handler->someMethod2(param3, param4);//call some other javascript method<br>

Thanks,
Eran.

谢谢,
伊兰。

回答by Cristian Sanchez

You cannot control or access a cross domain window unfortunately. This is done for security precautions. Do you have control over the other URL?

不幸的是,您无法控制或访问跨域窗口。这样做是为了安全预防措施。您可以控制其他 URL 吗?

However, if the window is on the same domainyou do have access to the window and its DOM.

但是,如果窗口在同一个域中,您确实可以访问该窗口及其 DOM。

var win = window.open("/page", "title");
win.someFunction();
var el = win.document.getElementById("id123");
//etc.