run function from child window in parent window

南楼画角 提交于 2019-11-29 18:24:27

It really depends on the context where you defined the function for the popup window. Assuming you attached the functions/data to the window object of the popup window, you can access it from the window handle returned by window.open (the window handle is the window object for the popup):

var w = window.open(somelocation,''); //has a function on `window` called "test"
w.test();

I'm going to assume that you understand how security sandboxes work for popup windows

Declare test() in your popup as follows:

window["test"] = function()
{
  alert("It works!");
}

Then open your popup from your main window:

var popup = window.open("popup.html", "The popup");

And call your function:

popup.window.test();

jsFiddle (won't work without the /show because of the cross-domain restriction!): http://jsfiddle.net/szK3F/show/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!