If you have a frame, image, or form with name=”URL” then this property will be shadowed on the document object and your code will break. In that case, document.URL will refer to the DOM node instead. Better to use properties of the global object as in window.location.href