javascript弹出问题在Internet Explorer中! [英] javascript popup issue In Internet Explorer !

查看:146
本文介绍了javascript弹出问题在Internet Explorer中!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用javascript打开弹出窗口时遇到问题,我有此功能在IE6和IE7中打开弹出窗口:

i have Problem with opening popups in javascript i have this function to open my popups in IE6 and 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();

}

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

it's working . i mean my new window opens but an error occurs. The Error Message is :

'window.open(...)'为null不是对象.
您要在此页面上计算运行脚本吗?

'window.open(...)' is null is not an object.
do you want to countinue running script on this page ?

然后我在onclick事件中有一个按钮,它将调用一个函数来关闭当前窗口并刷新打开器功能

then i have button in onclick event it's will call a function to close current window an refresh the opener function is

function refreshParent(location) 
{
  window.opener.location.href = location ; 
  window.close();
}

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

it's also gives me error : window.opener.location is null or not an object but i'm sure i'm passing correct parameters

我这样称呼它:

第二部分:

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

第一部分:

<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>

这真的使我感到困惑.请帮助;)

it's really confuse me . Please Help ;)

推荐答案

使用window.open打开的弹出窗口被弹出窗口阻止程序阻止,这是当今几乎所有现代浏览器的功能,即window.open的返回值. ()不是窗口对象,但为null.

When popup windows opened using window.open are blocked by a popup blocker, a feature of pretty much any modern browser these days, the return value of window.open() is not a window object, but null.

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

In order to circumvent these issues you would need to test the value returned by window.open() before attempting to invoke any methods on it.

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

Below is a piece of code to demonstrate how to go around this problem:

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();
}

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

In general, popup windows should be used only as a last resort or in controlled environments (internal company website, etc). Popup blockers tend to behave in very inconsistent ways and there may be more than a single popup blocker installed in a given browser so instructing the user on how to allow popups for a given website is not necessarily a solution. Example: IE7 + Google toolbar = two popup blockers.

如果我建议的话,也许您应该考虑使用类似以下的方式: http://jqueryui.com/demos/dialog/

If I may suggest, perhaps you should consider using something like this: http://jqueryui.com/demos/dialog/

优点很多:

  1. 皮肤漂亮,因此您可以创建更一致的外观以匹配您的网站.
  2. 没有弹出窗口阻止程序.
  3. 良好的API和文档,在大多数(即使不是全部)主要浏览器中也保持一致.

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

If you still require that the newly opened "window" contain an external URL, you could use an IFRAME inside the opened dialog window.

希望这会有所帮助,

骗子.

这篇关于javascript弹出问题在Internet Explorer中!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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