run function from child window in parent window(从父窗口中的子窗口运行函数)
问题描述
我有两个窗口:parent
和 popup
.显然 parent
有对 popup
的引用.现在在 popup
我有一个函数说
I have two windows: the parent
and the popup
. Obviously parent
has a reference to popup
. Now in popup
I have a function say
function test() { alert('test'); }
我想在 parent
中调用这个函数,类似于 popup.test();
.有没有办法做到这一点?我确实知道如何反过来做.只是声明
and I want to call this function in parent
, something like popup.test();
. Is there a way to do that? I do know how to do that the other way around. Just declaring
window.test = function() { alert('test'); }
并在弹出窗口中调用 window.opener.test();
工作正常.但是,这在我的情况下不起作用(我认为因为 window.opener
对象是一个引用,但是 window.open
和 window
在 popup
并不真正相关).有什么想法吗?
and calling window.opener.test();
in popup works fine. However this does not work in my case (I think because the window.opener
object is a reference, but window.open
and window
in popup
are not really related). Any ideas?
推荐答案
这实际上取决于您为弹出窗口定义函数的上下文.假设您将函数/数据附加到弹出窗口的 window
对象,您可以从 window.open
返回的窗口句柄(窗口句柄 是弹出窗口的window
对象):
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();
我假设您了解安全沙箱如何用于弹出窗口
这篇关于从父窗口中的子窗口运行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从父窗口中的子窗口运行函数


基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01