Dave's Brain

Browse - Programming Tips - How can I get the current URL?

Date: 2009dec28
Level: beginner
Language: javaScript
Platform: web

Q.  How can I get the current URL?

A.  Access the href member of the location object like this:

function displayCurrentUrl() { alert('Current URL is ' + location.href); }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.