Home  >  Article  >  Web Front-end  >  What are the ways to jump to js pages?

What are the ways to jump to js pages?

清浅
清浅Original
2019-02-16 10:45:2218218browse

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;http://www.php.cn&#39;;</script>

Method 2: Jump to the page by clicking the button

<input type="button" value="点击" onclick="location.href=&#39;http://www.php.cn/&#39;">

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;http://www.php.cn/&#39;,&#39;&#39;,&#39;height=200,width=300,scrollbars=yes&#39;) 
PHP中文网</a>

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 ="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

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 ="http://www.php.cn";
  
  }
}
  </script>
<a onclick="demo()">PHP中文网</a>

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!

Statement:
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
Previous article:How to use sort methodNext article:How to use sort method