Is javascript window.location crossbrowser?
15,368
Solution 1
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.
Solution 2
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.
Solution 3
window.location works in all major browsers
Author by
EBAG
Updated on June 17, 2022Comments
-
EBAG about 2 years
Is javascript code window.location functional in all new and old STANDARD POPULAR browsers?
-
Pekka about 13 yearsIndeed. JavaScript was first supported in Netscape 2.0.
-
folktrash over 9 yearsrelated: window.location.origin is missing in ie10 for windows phone, was added to ie11 msdn.microsoft.com/en-us/library/ie/dn736066(v=vs.85).aspx
-
nktssh over 9 yearswindow.location.origin polyfill: if (!window.location.origin) { window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: ''); }
-
Pedro Ferreira over 6 yearsTx for the "location.origin". In fact IE gets all bezerk! ;-)
-
Knu almost 4 yearsNot true for pathname.