>  기사  >  웹 프론트엔드  >  js에서 새 페이지로 이동하는 방법은 무엇입니까?

js에서 새 페이지로 이동하는 방법은 무엇입니까?

青灯夜游
青灯夜游원래의
2020-07-18 15:04:5217277검색

js에서 새 페이지로 이동하는 방법: 1. 이동하려면 location.href="새 페이지 URL"을 사용하세요. 2. 이동하려면 location.replace("새 페이지 URL")를 사용하세요. "새 페이지 URL")으로 이동합니다.

js에서 새 페이지로 이동하는 방법은 무엇입니까?

방법 1: location.href 사용

구문:

location.href="URL"

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>

js에서 새 페이지로 이동하는 방법은 무엇입니까?

방법 2: location.replace() 사용

구문:

location.replace("URL")

예 : 다른 웹 페이지로 이동하려면 location.replace() 메소드를 사용하세요

<!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>

js에서 새 페이지로 이동하는 방법은 무엇입니까?

방법 3: location.sign() 사용

구문: ​​

location.assign("URL")

예: location.sign() 메소드를 사용하여 다른 페이지로 이동 웹 페이지

<!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>

js에서 새 페이지로 이동하는 방법은 무엇입니까?

추천 튜토리얼: "JavaScript Video Tutorial"

위 내용은 js에서 새 페이지로 이동하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.