Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีดึง URL ปัจจุบันด้วย JavaScript

ใช้ Property window.location.href เพื่อดึง URL ปัจจุบัน

ตัวอย่าง

<!DOCTYPE html> <html> 
  <body> 
    <h3>Get current URL</h3> 
    <p id="test"></p> 
    <script> 
      document.getElementById("test").innerHTML = "URL of the page: " + window.location.href; 
    </script> 
  </body> 
</html>