javascript 弹出菜单和重定向 url
我用的是小盒子 http://sandbox.scriptiny.com/tinybox2/
打开弹出网页。 我希望当我单击网页上的链接时,弹出网页将关闭并自动重定向到链接网址我单击
我的 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>
但这看起来不起作用
I used Tinybox
http://sandbox.scriptiny.com/tinybox2/
to open a popup web page.
I hope when I click the links on the web page, the popup web page will close and automatically redirect to the link url I click
my javascript codes and html codes
<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>
but this looks like not to work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
parent.location.href
,而不是opener.location.href
。请参见下文:您还可以使用
top.location.href
:另一种选择是使用纯 HTML。虽然它不会先关闭弹出窗口,但它会将整个窗口重定向到您的 URL。请注意锚标记的
target
属性。注1:为什么要先关闭弹出窗口?如果您要重定向整个页面,只需重定向即可 - 无需关闭弹出窗口。
注 2: 仅当 iframe 中加载的页面与父窗口位于同一域中时,此操作才能正常工作(我假设这是因为您正在编写弹出代码) )。
Instead of
opener.location.href
, useparent.location.href
. See below:You could also use
top.location.href
:Another option would be to use pure HTML. Although it wouldn't close the pop up first, it would redirect the entire window to your URL. Notice the
target
attribute of the anchor tag.NOTE 1: Why close the pop up first? If you're redirecting the whole page, just redirect - no need to close the pop up.
NOTE 2: This will only work properly if the page that is loaded in the iframe is on the same domain as the parent window (I'm assuming that it is since you're writing the pop up code).