JavaScript window.location.href Property

You are Here:

JavaScript window.location.href Property

The window.location.href property returns the whole URL of the current page.

Note: This property allows the href to be updated.


HTML Online Editor
<!DOCTYPE html> <html> <body> <script> document.write("Page location: "+window.location.href); </script> </body> </html>



Return Value

StringReturns a string representing the whole URL of the current page.

More Examples


HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var txt = ""; txt += "<p>Page location: "+window.location.href+"</p>"; txt += "<p>Page hostname: "+window.location.hostname+"</p>"; txt += "<p>Page path: "+window.location.pathname+"</p>"; txt += "<p>Page protocol: "+window.location.protocol+"</p>"; txt += "<p>Port number: "+window.location.port+"</p>"; document.write(txt); </script> </body> </html>


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author