Home > Article > Web Front-end > What are the ways to jump to js pages?
The ways JavaScript implements page jumps include: direct jump, button jump through onclick function, window.open function to open a new window, and confirmation method to confirm whether to open a new window.
We will always encounter various page jumps during the development process, and different jump methods bring different experiences. Today I will share a few page jump methods in JavaScript, I hope it will be helpful to everyone.
[Recommended course: JavaScript Tutorial]
Method 1: Jump directly to the style
<script>window.location.href='http://www.php.cn';</script>
Method 2: Jump to the page by clicking the button
<input type="button" value="点击" onclick="location.href='http://www.php.cn/'">
By adding an onclick event to the button. But clicking on it will jump to the pre-set link address
Method 3: Open a new window directly on this page
<a href="javascript:" onClick="window.open('http://www.php.cn/','','height=200,width=300,scrollbars=yes') PHP中文网</a>
Through window. The open() function can open a new window in this page. scrollbars are used to set the scroll bar
Method 4: After the page stays for 5 seconds Jump to a new page
<script type="text/javascript"> function demo(){ window.location.href ="http://www.php.cn"; } setTimeout(demo,5000); </script> <a onclick="demo()">PHP中文网</a>
The setTimeout method is used to call a function or calculation expression after the specified number of milliseconds. In this example, the page jumps after 5s by setting the time parameter. Transfer
Method 5: Use the pop-up confirmation box on the page to choose whether to jump to a new page
<script type="text/javascript"> function demo(){ if(confirm("你确定要跳转到新的页面吗")){ window.location.href ="http://www.php.cn"; } } </script> <a onclick="demo()">PHP中文网</a>
Rendering:
The confirm method is used to display a dialog box with a specified message and OK and Cancel buttons. When OK is selected, Jump to a new page. When you choose to cancel, the page will not jump
Reference article for this article:
https://www.html.cn/doc/ javascript/timing/
https://www.html.cn/doc/javascript/window-location/
Summary: The above is the entire content of this article. I hope that through this This article lets everyone learn to use JavaScript to implement various page jump methods
The above is the detailed content of What are the ways to jump to js pages?. For more information, please follow other related articles on the PHP Chinese website!