Home > Web Front-end > JS Tutorial > How to implement page jump in javascript

How to implement page jump in javascript

青灯夜游
Release: 2023-01-04 09:34:48
Original
56335 people have browsed it

js page jump method: 1. Use "location.href="URL""; 2. Use "location.replace("URL")"; 3. Use "location.assign("URL" )"; 4. Use "window.open("URL")".

How to implement page jump in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to implement page jump using JavaScript:

1. Use the location.href attribute to jump to other web pages

Syntax:

location.href="URL";
Copy after login

Example:

<!DOCTYPE html>
<html>
    <head>
		<meta charset="UTF-8">
    </head> 
    <body> 
      <p>这是<i>location.href</i>方式的示例</p> 
      <button onclick="myFunc()">点击这里</button> 
        
      <!--重定向到其他网页的脚本-->   
      <script> 
         function myFunc() { 
           window.location.href="https://www.php.cn"; 
         } 
      </script> 
   </body> 
</html>
Copy after login

2. Use the location.replace() method to jump to other web pages

Grammar:

location.replace("URL");
Copy after login

Example:

<!DOCTYPE html>
<html>
    <head>
		<meta charset="UTF-8">
    </head> 
    <body> 
      <p>这是<i>location.replace()</i>方式的示例</p> 
      <button onclick="myFunc()">点击这里</button> 
        
      <!--重定向到其他网页的脚本-->   
      <script> 
         function myFunc() { 
          location.replace("https://www.php.cn"); 
         } 
      </script> 
   </body> 
</html>
Copy after login

[Recommended learning: javascript advanced tutorial]

3. Use location.assign () method to jump to other web pages

Syntax:

location.assign("URL")
Copy after login

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    </head> 
    <body> 
      <p>这是<i>location.assign()</i>方式的示例</p> 
      <button onclick="myFunc()">点击这里</button> 
        
      <!--重定向到其他网页的脚本-->   
      <script> 
         function myFunc() { 
          location.assign("https://www.php.cn"); 
         } 
      </script> 
   </body> 
</html>
Copy after login

4. Use the window.open() method to jump to Other web pages

Grammar:

window.open("URL");
Copy after login

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    </head> 
    <body> 
      <p>这是<i>window.open()</i>方式的示例</p> 
      <button onclick="myFunc()">点击这里</button> 
        
      <!--重定向到其他网页的脚本-->   
      <script> 
         function myFunc() { 
          window.open("https://www.php.cn"); 
         } 
      </script> 
   </body> 
</html>
Copy after login

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of How to implement page jump in javascript. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template