Javascript Browser Location href Property get

Introduction

Return the entire URL of the current page:

var x = location.href;

Click the button to display the entire URL of the current page.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  ww  w. j  av a2 s.  co m*/
  var x = location.href;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The href property sets or gets the entire URL of the current page.

The href property returns a String representing the entire URL of the page, including the protocol.




PreviousNext

Related