Return the entire URL of the current page:
var x = location.href;
Click the button to display the entire URL of the current page.
<!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.