当前位置: 代码迷 >> Web前端 >> IE上window.open()第二个参数
  详细解决方案

IE上window.open()第二个参数

热度:139   发布时间:2012-09-08 10:48:07.0
IE下window.open()第二个参数

今天在IE下遇到了一个对于我来说的一个诡异的问题,

window.open("test02.php","just test","menubar=1,location=1");

window.open("test02.php","juestest","menubar=1,location=1");

这本来是一个很简单的句子,第一句在IE下面不起作用,第二句就可以,区别在于第二个参数多了一个空格,自己还2B一样以为发现了IE的bug,结果别人深深的鄙视了。

?

下面是别人的总结:

?

http://stackoverflow.com/questions/710756/ie8-var-w-window-open-message-invalid-argument

?

This is an old posting but maybe still useful for someone.

I had the same error message. In the end the problem was an invalid name for the second argument, i.e., I had a line like:

? ?window.open('/somefile.html', 'a window title', 'width=300');

The problem was 'a window title' as it is not valid. It worked fine with the following line:

? ?window.open('/somefile.html', '', 'width=300');

In fact, reading carefully I realized that Microsoft does not support a?name?as second argument. When you look at the?official documentation page, you see that Microsoft only allows the following arguments, If using that argument at all:

  • _blank
  • _media
  • _parent
  • _search
  • _self
  • _top

我算是213到家了,还以为是IE的bug....

think firest,check secound,search third,ask last

使用JavaScript中,父窗口调用子窗口中的函数 及 子窗口调用父窗口中的函数

父窗口调用子窗口函数实现是挺简单的,如下:
var wnd = window.open("XXX.html");
wnd.showDatas(datas);
以上代码中,showDatas是定义在子窗口的函数,datas是父窗口要给子窗口的数据。
需要注意的事,使用open语句打开窗口后,窗口未必能把所有代码全部载入,因此showDatas函数未必调用有效。
如果要有效,可以先把数据传递给子窗口,再在子窗口中延时调用showDatas函数。
如此,父窗口中的代码如下:
var wnd = window.open("XXX.html");
wnd.datas=datas;// 传递数据给子窗口
子窗口中的代码如下:
setTimeout(showDatas(window.datas),1000);// 延时时间可进行调整。
如上,父窗口调用子窗口函数才算完美。

反过来,子窗口要调用父窗口的函数要用opener对象,如:
opener.showMessages(msgs);
以上代码中,showMessages是定义在父窗口的函数,msgs是子窗口要给父窗口的数据。
  相关解决方案