mickeymouse 0 Posted December 26, 2019 Report Share Posted December 26, 2019 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.... Quote Link to post Share on other sites
dsonesuk 913 Posted December 28, 2019 Report Share Posted December 28, 2019 All javascript requires an event to run code, onload, onclick etc. There isn't an event for just thinking run this code. Once you decide which event to use you can then use window.location to take you to specific page. https://www.w3schools.com/howto/howto_js_redirect_webpage.asp Quote Link to post Share on other sites
mickeymouse 0 Posted December 29, 2019 Author Report Share Posted December 29, 2019 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! Quote Link to post Share on other sites
dsonesuk 913 Posted December 29, 2019 Report Share Posted December 29, 2019 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. Quote Link to post Share on other sites
Steven1 2 Posted January 6, 2020 Report Share Posted January 6, 2020 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> Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.