JavaScript: How to get the URL of the current web page?

by Yang Yang on July 22, 2010

To get the URL address of the current page with JavaScript, simply return the value of window.location.href:

document.write(window.location.href);

Which is the same with:

document.write(location.href);

There’s much more you can do with the JavaScript Location Object such as redirecting to another URL.

Comments on this entry are closed.

Previous post:

Next post: