Computer >> Máy Tính >  >> Lập trình >> Javascript

Làm cách nào để lấy URL hiện tại bằng JavaScript?


Để nhận URL hiện tại bằng JavaScript, hãy sử dụng window.location. href tài sản -

Ví dụ

Bản trình diễn trực tiếp

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