P
Peter Michaux
Setting the location.href state in Safari sends the browser into a
indefinite loading state [1]. This has been discussed here before [2]
with no solution offered that I can find in the archives. One of the
Webkit developers on IRC directed me to a web page [3] with this
clever and useful solution[4].
function setHash(hash) {
if (navigator.userAgent.match(/Safari/i)) {
if
(parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Safari')
+ 7)) < 412) {
// the form doesn't need to be attached to the document.
var f = document.createElement('form');
f.action = hash;
f.submit();
} else {
var evt = document.createEvent('MouseEvents');
evt.initEvent('click', true, true);
var anchor = document.createElement('a');
anchor.href = hash;
anchor.dispatchEvent(evt);
}
} else {
window.location.hash = hash;
}
}
The navigator.userAgent sniff is, of course, repugnant and I don't
know if there is a way to directly feature test or use multiple object
inference to determine version number. The time required to build
versions of webkit and safari from source code for version around 412
seems unwarranted when the above code "works".
It is interesting to think that in this case there may not be any
other tests that could be used. It could be that version 412 only
changed the navigator.userAgent string, broke the old workaround and
enabled the new workaround. Such a minimal change set may require use
of navigator.userAgent.
Peter
[1] current nightly webkit builds are fixed
[2] <URL:
http://groups.google.com/group/comp...=location.href+safari&rnum=3#6f6d9106694b0e6c>
[3] <URL: http://swfaddress.svn.sourceforge.n.../js/swfaddress.js?revision=149&view=markup[4] rewritten here with no external dependencies.
indefinite loading state [1]. This has been discussed here before [2]
with no solution offered that I can find in the archives. One of the
Webkit developers on IRC directed me to a web page [3] with this
clever and useful solution[4].
function setHash(hash) {
if (navigator.userAgent.match(/Safari/i)) {
if
(parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Safari')
+ 7)) < 412) {
// the form doesn't need to be attached to the document.
var f = document.createElement('form');
f.action = hash;
f.submit();
} else {
var evt = document.createEvent('MouseEvents');
evt.initEvent('click', true, true);
var anchor = document.createElement('a');
anchor.href = hash;
anchor.dispatchEvent(evt);
}
} else {
window.location.hash = hash;
}
}
The navigator.userAgent sniff is, of course, repugnant and I don't
know if there is a way to directly feature test or use multiple object
inference to determine version number. The time required to build
versions of webkit and safari from source code for version around 412
seems unwarranted when the above code "works".
It is interesting to think that in this case there may not be any
other tests that could be used. It could be that version 412 only
changed the navigator.userAgent string, broke the old workaround and
enabled the new workaround. Such a minimal change set may require use
of navigator.userAgent.
Peter
[1] current nightly webkit builds are fixed
[2] <URL:
http://groups.google.com/group/comp...=location.href+safari&rnum=3#6f6d9106694b0e6c>
[3] <URL: http://swfaddress.svn.sourceforge.n.../js/swfaddress.js?revision=149&view=markup[4] rewritten here with no external dependencies.