
Originally Posted by
fileserverdirect
jscheuer1'sKinda Works*
*works in IE\FF, but not in Safari, IE: Mac.
Is it possable to get this script to work cross-browser (ie Works to 100%
I cannot test code in a browser/on a machine that I don't have. As for IE Mac, almost nothing works in that browser which hasn't been supported by anyone in over 3 years. I did test in Safari 3 Win. Works fine in that. Are you using the most recent Safari Mac? If you go far enough back in the version history of any browser, many scripts will cease working.
In any case, (barring something very unusual) the code will work in any DOM level 2 compliant browser.
The chances that any given browser will respond at that level are increased if the page that the script is on has a valid URL HTML 4.01 DOCTYPE. XHTML DOCTYPEs, HTML DOCTYPEs for versions lower than 4.01 or HTML 4.01 DOCTYPEs without valid URL can all throw some browsers into quirks mode, where virtually anything can happen.
Some tests to try on the 'offending' browsers:
Code:
alert(document.getElementsByTagName);
Code:
if(document.getElementsByTagName)
alert(document.getElementsByTagName('script').length);
Here is a modified version that might make those other browsers happy:
Code:
function getQueryValue(var_name) {
var s = document.documentElement.getElementsByTagName('script'),
m = (new RegExp('[?&;]' + var_name + '=([^&;#]*)')).exec(s[s.length-1].getAttribute('src', 0));
return m ? unescape(m[1]) : null;
}
Also try:
Code:
function getQueryValue(var_name) {
var s = document.getElementsByTagName('script'),
m = (new RegExp('[?&;]' + var_name + '=([^&;#]*)')).exec(s[s.length-1].getAttribute('src', 0));
return m ? unescape(m[1]) : null;
}
and:
Code:
function getQueryValue(var_name) {
var s = document.documentElement.getElementsByTagName('script'),
m = (new RegExp('[?&;]' + var_name + '=([^&;#]*)')).exec(s[s.length-1].src);
return m ? unescape(m[1]) : null;
}
All of which will also work on level 2 browsers.
Edit: I thought of some more things. If it can be determined what about the script that non-supporting browsers don't like, a test for that may be devised and either a fall-back (default) value may be used with them, or a fall-back procedure. Also, if your server supports asp, PHP or any other server side language that supports query 'gets', the query value may be passed to the script using that language for 100% of browsers.
Bookmarks