打开子窗口时传递一个简单的字符串

Pass a simple string when opening a child window

本文关键字:一个 简单 字符串 窗口      更新时间:2023-09-26

在父窗口中:

window.open('page.php','nameIWant','toolbar=no')

如何从新窗口代码中获取 window.open() 中指定的目标。

我试图检索document.title,document.name 和document.target,没有人给我"nameIWant"或者有没有一种简单的方法可以在打开时获取字符串,该方法适用于 IE8。

您不命名文档,而是命名新窗口。尝试在新打开的窗口中window.name

获取

子窗口的document对象只是引用新打开的窗口并从中获取document对象:

http://jsfiddle.net/3pQk6/

var child = window.open();
//set title
child.document.title = 'foo'
//text node in child window's body
child.document.body.appendChild(document.createTextNode('bar'));​​​