Reputation: 19
I'm writing a code in JavaScript wherein if the condition is null/false, the browser automatically redirects to another page. The only question is what are the codes for this block? Please help.
if(condition==false){
//redirect code
}
else
continue;
Upvotes: 0
Views: 410
Reputation: 611
window.location = "URL TO REDIRECT";
or
window.location.replace("URL TO REDIRECT");
or
window.location.assign("URL TO REDIRECT");
or
window.location.href = "URL TO REDIRECT";
Remember to include "http://" or "https://" with your url. :)
Upvotes: 1
Reputation: 313
try this tested!
window.location.assign("URL");
e.g.
window.location.assign("http://www.google.com");
Upvotes: 0
Reputation: 3096
:) use code bellow
if( condition== null /false )
{
alert(" Ohhooo.. Redirected ");
window.location.replace('http://url');
// another code
// location.href = "url.html";
// u can also use time out code after time page redirect
//setTimeout("location.href = 'http://url';",1500);
}
Upvotes: 0
Reputation: 67
if(condition==false){
window.location.replace("http://stackoverflow.com");
}
Upvotes: 1