javascript弹出问题在Internet Explorer中!

meh*_*hdi 4 javascript internet-explorer popup

我有问题在javascript中打开弹出窗口我有这个功能在IE6和IE7中打开我的弹出窗口:

function open_window(Location,w,h) //opens new window
{
  var win = "width="+w+",height="+h+",menubar=no,location=no,resizable,scrollbars,top=500,left=500";
  alert(win) ;
  window.open(Location,'newWin',win).focus();

}
Run Code Online (Sandbox Code Playgroud)

它正在工作.我的意思是我的新窗口打开但发生错误.错误消息是:

'window.open(...)'为null不是对象.
你想在这个页面上计算运行脚本吗?

然后我在onclick事件中有按钮它会调用一个函数关闭当前窗口刷新开启功能

function refreshParent(location) 
{
  window.opener.location.href = location ; 
  window.close();
}
Run Code Online (Sandbox Code Playgroud)

它也给了我错误:window.opener.location是null或不是对象,但我确定我传递了正确的参数

我称之为:

第二部分:

<input type="button" name="pay" value="test" onclick="refreshParent('index.php?module=payment&task=default')" >
Run Code Online (Sandbox Code Playgroud)

第一部分:

<a onclick="javascript:open_window('?module=cart&task=add&id=<?=$res[xproductid]?>&popup=on','500' , '500')"  style="cursor:pointer" id="addtocard"> <img src="../images/new_theme/buy_book.gif" width="123" border="0"/> </a>
Run Code Online (Sandbox Code Playgroud)

这让我很困惑.请帮忙 ;)

Lio*_*hen 6

当使用window.open打开的弹出窗口被弹出窗口阻止程序阻止时,这几天是几乎所有现代浏览器的一个特性,window.open()的返回值不是窗口对象,而是null.

为了避免这些问题,您需要在尝试调用其上的任何方法之前测试window.open()返回的值.

下面是一段代码,演示如何解决此问题:

function open_window(Location,w,h) //opens new window
{
  var options = "width=" + w + ",height=" + h;
  options += ",menubar=no,location=no,resizable,scrollbars,top=500,left=500";

  var newwin = window.open(Location,'newWin',options);

  if (newwin == null)
  {
    // The popup got blocked, notify the user
    return false;
  }

  newwin.focus();
}
Run Code Online (Sandbox Code Playgroud)

通常,弹出窗口应仅用作最后的手段或受控环境(公司内部网站等).弹出窗口阻止程序往往表现得非常不一致,并且在给定的浏览器中可能安装了多个弹出窗口阻止程序,因此指示用户如何允许给定网站的弹出窗口不一定是解决方案.示例:IE7 + Google工具栏=两个弹出窗口阻止程序.

如果我建议,也许你应该考虑使用这样的东西:http: //jqueryui.com/demos/dialog/

优点很多:

  1. Skinnable,因此您可以创建更一致的外观以匹配您的网站.
  2. 没有弹出窗口拦截器.
  3. 良好的API和文档在大多数(如果不是全部)主流浏览器中都是一致的.

如果仍然要求新打开的"窗口"包含外部URL,则可以在打开的对话框窗口中使用IFRAME.

希望这可以帮助,

利奥尔.