Monday, 26 August 2013

How to do a page redirect using javascript?

How to do a page redirect using javascript?

I am currently using this code which is working great except for iframes :
var domains = ["domain1.com", "domain2.com", "domain3.com"];
if (domains.indexOf(document.location.hostname) == -1 &&
document.cookie.indexOf('redirected=1') == -1) {
document.cookie = "redirected=1";
window.location.replace('http://domain1.com');
}
alert("Join our main website ==> http://domain1.com");
but when my website is iframed in other sites the code doesn't work, and
if i use window.location.open or window.location.href it will be blocked
by popup blockers.
is there another way to do a redirect or a page open without being stopped
by popup blockers or just a redirect that can redirect the whole page that
has the iframe to another page ?
Thanks in advance.
-tool

No comments:

Post a Comment