Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is javascript window.location crossbrowser?

Is javascript code window.location functional in all new and old STANDARD POPULAR browsers?

like image 662
EBAG Avatar asked Apr 10 '11 22:04

EBAG


People also ask

What is Javascript window location?

The location property of a window (i.e. window. location ) is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window. location object can be accessed without window.

Does window location work in all browsers?

All modern browsers map document. location to the window. location but you can prefer window.

Is it good to use window location href?

See the question IE incompatability with window. location. href. But yes, it's better to use href as a property, which will work in any browser, including IE.

What is the purpose of the window location object in Javascript?

The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.


2 Answers

window.location, which shares the same structure as document.location should be identical between modern browsers for the following properties:

  • hash (except in FireFox ~< 16.0 where there was a bug with encoding)
  • hostname
  • href
  • pathname
  • port
  • protocol
  • search
  • reload()
  • replace()

Known Differences:

  • Only Webkit has location.origin at the time of writing.
like image 97
Purrell Avatar answered Sep 28 '22 06:09

Purrell


I can't say 'all old browsers' since it may not work in Netscape Navigator 0.9 but yeah this is in the standard and is very widely supported.

like image 26
Jim Blackler Avatar answered Sep 28 '22 07:09

Jim Blackler