If you insist on keeping the redirect on the client side - You can set the body to display:none
, and then in the else
branch of your conditional in JavaScript - show it:
CSS
body{
display:none;
}
JS:
if(someCondition){
location.hred = "http://othersite";
} else {
document.body.style.display = "block";
}
Note that this has the disadvantage of showing a blank page to people who don't have JS enabled, so you might want to do it for a less 'drastic' tag than <body>
.