简体   繁体   English

javascript 弹出菜单和重定向 url

[英]javascript popup menu and redirect url

I used Tinybox http://sandbox.scriptiny.com/tinybox2/我用的是 Tinybox http://sandbox.scriptiny.com/tinybox2/

to open a popup web page.打开弹出 web 页面。 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我希望当我单击 web 页面上的链接时,弹出 web 页面将关闭并自动重定向到链接 url 我单击

my javascript codes and html codes我的 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>

but this looks like not to work但这看起来不起作用

Instead of opener.location.href , use parent.location.href .而不是opener.location.href ,使用parent.location.href See below:见下文:

function closeAndGotoURL {
    TINY.box.hide();
    parent.location.href='http://www.google.com';
}

You could also use top.location.href :您也可以使用top.location.href

function closeAndGotoURL {
    TINY.box.hide();
    top.location.href='http://www.google.com';
}

Another option would be to use pure HTML.另一种选择是使用纯 HTML。 Although it wouldn't close the pop up first, it would redirect the entire window to your URL.虽然它不会首先关闭弹出窗口,但它会将整个 window 重定向到您的 URL。 Notice the target attribute of the anchor tag.注意锚标记的target属性。

<a href="http://www.google.com" target="_top">

NOTE 1: Why close the pop up first?注意1:为什么要先关闭弹出窗口? 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).注意 2:只有在 iframe 中加载的页面与父 window 位于同一域中时,这才能正常工作(我假设这是因为您正在编写弹出代码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM