window.open() 与 Firefox 3 中的锚点配合不佳
下面的 JavaScript 旨在打开一个新窗口并跳转到指定的锚点,在 IE 中效果很好。不幸的是,在 Firefox 中,它会打开窗口,但不会跳转到锚点。
我已经为这个问题苦苦挣扎了几天(搜索和修改),但无济于事。
如果有人对我如何让它在 IE 和 Mozilla 浏览器中按预期工作有任何见解,我将永远感激不已。
这是包含 window.open() 的 javascript 函数以及调用包含 window.open() 的函数的链接:
<html>
<head>
<script language=javascript>
function openPopupWindow_Why(sPopupUrl, sPopupLabel)
{
window.open(sPopupUrl, sPopupLabel, 'toolbar=no,resizable=yes,
scrollbars=yes,height=250,width=450', false);
return false;
}
</script>
</head>
<body>
<A onclick="openPopupWindow_Why('MyProfile_WhyAsk.htm#ethnicity', 'Why')"
href="javascript:void(0)" class="WhyAsk">Why do we ask?</a>
</body>
</html>
这是通过 window.open() 打开的页面上的 HTML 锚点:
<tr>
<td align="center">
<a name="#ethnicity"> </a>
</td>
</tr>
The following javascript, intended to open a new window and jump to a specified anchor, works great in IE. Unfortunately, in Firefox, it opens the window, but it doesn't jump to the anchor.
I've been struggling with this problem for a couple of days now (searches and modifications) to no avail.
If anybody has any insight as to how I can get this to work as intended in both IE and Mozilla browsers, I'd be forever grateful.
Here's the javascript function containing window.open() and the link calling the function containing window.open():
<html>
<head>
<script language=javascript>
function openPopupWindow_Why(sPopupUrl, sPopupLabel)
{
window.open(sPopupUrl, sPopupLabel, 'toolbar=no,resizable=yes,
scrollbars=yes,height=250,width=450', false);
return false;
}
</script>
</head>
<body>
<A onclick="openPopupWindow_Why('MyProfile_WhyAsk.htm#ethnicity', 'Why')"
href="javascript:void(0)" class="WhyAsk">Why do we ask?</a>
</body>
</html>
Here's the HTML anchor on the page that's opened by window.open():
<tr>
<td align="center">
<a name="#ethnicity"> </a>
</td>
</tr>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试从种族锚点名称中删除 #,如下所示:
至少适用于 IE、Firefox 和 Chrome
Try removing the # from the ethnicity anchor name like so:
Works in at least IE, Firefox and Chrome