简体   繁体   中英

javascript popup menu and redirect url

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

Instead of opener.location.href , use parent.location.href . See below:

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

You could also use top.location.href :

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

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.

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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