Jump to content

Recommended Posts

Posted

How do I open a new page (replacing the current one) in inline code, i.e. without the need to click  something?

e.g.,

if(x=y)
	open new page
else{continue....

 

 

Posted

It's not a case of "just thinking".  There is a decision making via the "if" statement so I don't see why there shouldn't be a facility to go to a new page based on the decision.  One should be able to do "anything" without human intervention.  However, it seems that is not possible with website programming - something I consider a deficiency.

Nonetheless, thanks for your help!

Posted

Before it reaches the if/else condition, it has to be triggered by interaction with the browser/app/program by an event. THAT! is the only discision made, the if/else condition processes data passed to it to determine what action to take on the data passed to it.

  • 2 weeks later...
Posted

You don't need JavaScript at all. I was formerly using it for inline code but have beefed up my security settings by disallowing all forms of inline code, now I use a meta tag like this;

<!-- Replace the zero with how many seconds of delay you want before the refresh is triggered -->
<meta http-equiv='refresh' content='0;url=https://example.com' />

If you really want to use JavaScript you could use this;

<script>
// The following replaces the current URL with a new one
window.location.replace('https://example.com');

// Or with a time delay in microseconds (currently set at 2 seconds)
setTimeout( function() {window.open('https://example.com','_self')}, 2000);
</script>

 

  • 1 year later...
Posted

Using replace() is better for javascript redirect , because it does not keep the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco.

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...