我可以将 JavaScript 变量传递给另一个浏览器窗口吗? [英] Can I pass a JavaScript variable to another browser window?

查看:29
本文介绍了我可以将 JavaScript 变量传递给另一个浏览器窗口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,它会生成一个弹出式浏览器窗口.我在父浏览器窗口中有一个 JavaScript 变量,我想将它传递给弹出的浏览器窗口.

I have a page which spawns a popup browser window. I have a JavaScript variable in the parent browser window and I would like to pass it to the popped-up browser window.

有没有办法做到这一点?我知道这可以在同一个浏览器窗口中跨帧完成,但我不确定是否可以跨浏览器窗口完成.

Is there a way to do this? I know this can be done across frames in the same browser window but I'm not sure if it can be done across browser windows.

推荐答案

前提是这些窗口来自同一个安全域,并且你有另一个窗口的引用,是的.

Provided the windows are from the same security domain, and you have a reference to the other window, yes.

Javascript 的 open() 方法返回对创建的窗口(或现有窗口,如果它重用现有窗口)的引用.以这种方式创建的每个窗口都会应用一个属性window.opener",指向创建它的窗口.

Javascript's open() method returns a reference to the window created (or existing window if it reuses an existing one). Each window created in such a way gets a property applied to it "window.opener" pointing to the window which created it.

然后可以使用 DOM(取决于安全性)访问另一个的属性,或其文档、框架等.

Either can then use the DOM (security depending) to access properties of the other one, or its documents,frames etc.

这篇关于我可以将 JavaScript 变量传递给另一个浏览器窗口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆