![](/img/trans.png)
[英]javascript open popup without menu/url/titlebar/scrollbar/anything
[英]javascript popup menu and redirect url
我用的是 Tinybox http://sandbox.scriptiny.com/tinybox2/
打开弹出 web 页面。 我希望当我单击 web 页面上的链接时,弹出 web 页面将关闭并自动重定向到链接 url 我单击
我的 javascript 代码和 html 代码
<script type="text/javascript" src="tinybox.js"></script>
<script type="text/javascript">
function openJS(){}
function closeJS(){}
function closeAndGotoURL{
TINY.box.hide();
opener.location.href='http://www.google.com';
}
<a href="#" onclick="TINY.box.show({iframe:'webpage2.html',boxid:'frameless',width:750,height:450,fixed:false,maskid:'bluemask',maskopacity:40,closejs:function(){closeJS()}})">Open page2</a>
//...below is on webpage2.html, it does not work
<a href="#" onclick="closeAndGotoURL()"> Click </a>
但这看起来不起作用
而不是opener.location.href
,使用parent.location.href
。 见下文:
function closeAndGotoURL {
TINY.box.hide();
parent.location.href='http://www.google.com';
}
您也可以使用top.location.href
:
function closeAndGotoURL {
TINY.box.hide();
top.location.href='http://www.google.com';
}
另一种选择是使用纯 HTML。 虽然它不会首先关闭弹出窗口,但它会将整个 window 重定向到您的 URL。 注意锚标记的target
属性。
<a href="http://www.google.com" target="_top">
注意1:为什么要先关闭弹出窗口? 如果您要重定向整个页面,只需重定向 - 无需关闭弹出窗口。
注意 2:只有在 iframe 中加载的页面与父 window 位于同一域中时,这才能正常工作(我假设这是因为您正在编写弹出代码)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.