Home > Web Front-end > JS Tutorial > body text

What are the ways to jump to js pages?

清浅
Release: 2019-02-18 09:09:58
Original
18199 people have browsed it

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.

What are the ways to jump to js pages?

[Recommended course: JavaScript Tutorial]

Method 1: Jump directly to the style

<script>window.location.href=&#39;//m.sbmmt.com&#39;;</script>
Copy after login

Method 2: Jump to the page by clicking the button

<input type="button" value="点击" onclick="location.href=&#39;//m.sbmmt.com/&#39;">
Copy after login

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(&#39;//m.sbmmt.com/&#39;,&#39;&#39;,&#39;height=200,width=300,scrollbars=yes&#39;) 
PHP中文网</a>
Copy after login

Through window. The open() function can open a new window in this page. scrollbars are used to set the scroll bar

What are the ways to jump to js pages?

Method 4: After the page stays for 5 seconds Jump to a new page

<script type="text/javascript">
  function demo(){
  window.location.href ="//m.sbmmt.com";
  }
  setTimeout(demo,5000);
  </script>
<a onclick="demo()">PHP中文网</a>
Copy after login

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

What are the ways to jump to js pages?

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 ="//m.sbmmt.com";
  
  }
}
  </script>
<a onclick="demo()">PHP中文网</a>
Copy after login

Rendering:

What are the ways to jump to js pages?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!