Javascript 在一个浏览器上工作但在另一个浏览器上不工作的弹出窗口
为什么弹出窗口可以在一个浏览器上工作(在firefox上工作,firefox开发者版),而不能在另一个浏览器上工作(不在Internet explorer上,部分在Chrome上)?在某些情况下,弹出窗口可以在浏览器上的某个网站的某些页面上工作,但在转到该网站的另一个页面时,同一弹出窗口将无法工作。弹出窗口在页脚中Javascript 在一个浏览器上工作但在另一个浏览器上不工作的弹出窗口,javascript,popupwindow,Javascript,Popupwindow,为什么弹出窗口可以在一个浏览器上工作(在firefox上工作,firefox开发者版),而不能在另一个浏览器上工作(不在Internet explorer上,部分在Chrome上)?在某些情况下,弹出窗口可以在浏览器上的某个网站的某些页面上工作,但在转到该网站的另一个页面时,同一弹出窗口将无法工作。弹出窗口在页脚中 <a href="#" onclick="PopupCenter('/terms_conditions.aspx','','550','700')">Terms
<a href="#" onclick="PopupCenter('/terms_conditions.aspx','','550','700')">Terms
& Conditions</a>
最好在
onclick
处理程序中返回false
。该链接通常指向您希望它显示的页面,而在事件处理程序中调用弹出脚本。在函数中返回false
时,会阻止浏览器跟随链接
这可能会也可能不会影响浏览器的行为,具体取决于您使用的软件。关于这个话题有一篇很好的文章,涵盖了大部分的陷阱
请尝试以下代码:
function PopupCenter(pageURL, title, w, h) {
left = (screen.width / 2) - (w / 2);
top = (screen.height / 2) - (h / 2);
targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
if (window.focus) {
targetWin.focus();
}
return false;
}
完整演示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Popup Demo</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
<!--
function PopupCenter(pageURL, title, w, h) {
left = (screen.width / 2) - (w / 2);
top = (screen.height / 2) - (h / 2);
targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
if (window.focus) {
targetWin.focus();
}
return false;
}
// -->
</script>
</head>
<body>
<div>
<a href="#" onclick="return PopupCenter('terms_conditions.aspx', '', '550', '700')">Terms & Conditions</a>
</div>
</body>
</html>
弹出式演示
你的PopupCenter()
函数是什么样子的?我发布了代码。。它在某些浏览器上工作,但在其他浏览器上不工作。我要求的是PopupCenter()
函数的代码,而不是调用它的标记。该方法会发生什么情况?忘记添加弹出功能如果我取出pageURL并只放入URL,我现在会得到一个弹出窗口(在Internet Explorer中),但有一个页面未找到错误。我在上面的0x800a138f中得到一个错误-JavaScript运行时错误:Object expectedI在不知道代码结构的情况下无法判断,但我认为您没有正确地在后续页面中包含JavaScript代码。你能提供一个链接到你的网站还是它还没有上线?大多数浏览器都有一个控制台窗口,后续页面上是否会出现任何错误消息?我建议使用Opera Dragonfly或Firefox的Firebug插件等工具。请访问-转到页面底部,单击隐私政策和其他链接“条款与条件”。应为这两个选项显示一个弹出窗口。现在转到页面顶部的另一个黑色页面(罗马、梵蒂冈、威尼斯、佛罗伦萨、米兰)-尝试相同的过程后,弹出窗口不会出现在IE或Chrome中,但在firefox和safari中有效。错误:未捕获类型错误:window.open不是一个函数。是否在后续页面的范围内定义另一个名为open
的变量?如果这样做,则可能会覆盖open
,并且window.open()
不再是有效的函数。例如,window.open=false;window.open(“foobar”)
将引发您描述的错误。是的,刚刚检查了您的链接。您正在重新定义open
。在名为filterOptions1
的div
后面有一块jQuery代码。您应该将var重命名为open代码>类似于var myOpen例如,代码>那里。其他变量,如open1
、open2
和open3
都很好,它们不会干扰window.open()
。
function PopupCenter(pageURL, title, w, h) {
left = (screen.width / 2) - (w / 2);
top = (screen.height / 2) - (h / 2);
targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
if (window.focus) {
targetWin.focus();
}
return false;
}
<a href="#" onclick="return PopupCenter('terms_conditions.aspx', '', '550', '700')">Terms & Conditions</a>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Popup Demo</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
<!--
function PopupCenter(pageURL, title, w, h) {
left = (screen.width / 2) - (w / 2);
top = (screen.height / 2) - (h / 2);
targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
if (window.focus) {
targetWin.focus();
}
return false;
}
// -->
</script>
</head>
<body>
<div>
<a href="#" onclick="return PopupCenter('terms_conditions.aspx', '', '550', '700')">Terms & Conditions</a>
</div>
</body>
</html>