Javascript popup menu and redirect url

I used Tinybox http://sandbox.scriptiny.com/tinybox2/

to open a popup webpage. Hopefully when I click the links on the webpage, the pop-up webpage closes and automatically redirects to the URL of the link 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 it looks like it doesn't work

+4
source share
1 answer

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

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

You can also use top.location.href :

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

Another option is to use pure HTML. Although it will not close the popup first, it redirects the entire window to your URL. Note the target attribute of the anchor tag.

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

NOTE 1: Why close the popup first? If you redirect the entire page, just redirect - no need to close the pop-up window.

NOTE 2: This will only work if the page loaded in the iframe is in the same domain as the parent window (I assume this is the case, the pop-up code).

0
source

All Articles