Not in my opinion. But I'm tired of arguing that point. Here's a workaround (may need further tweaking):
Code:
function toggleColor() {
lastColor = lastColor == 'red' ? 'green' : 'red';
myObject = document.getElementById('myStyle');
if (myObject.sheet) { // Mozilla style w/kludge to overcome base href in browsers that cannot read cssRules (Chrome, Safari, perhaps others)
var base = document.getElementsByTagName('base'), baseHref;
if(base.length && !myObject.sheet.cssRules){
baseHref = base[base.length - 1].href;
base[base.length - 1].href = '#';
}
myObject.sheet.cssRules[0].style.color = lastColor;
if(base.length && typeof baseHref !== 'undefined'){
base[base.length - 1].href = baseHref;
}
}
if (myObject.styleSheet) { myObject.styleSheet.rules[0].style.color = lastColor; } // IE style
}
However, the base tag can present other problems. Try it in Firefox with:
HTML Code:
<base target="_blank">
What fun!
That can be fixed by avoiding firing of this:
Code:
<a href="javascript: toggleColor();" . . .
like so:
Code:
<a href="javascript: toggleColor();" onclick="toggleColor(); return false;">
Yeah it needed tweaking:
Code:
function toggleColor() {
lastColor = lastColor == 'red' ? 'green' : 'red';
myObject = document.getElementById('myStyle');
if (myObject.sheet) { // Mozilla style w/kludge to overcome base href in browsers that cannot read cssRules (Chrome, Safari, perhaps others)
var base = document.getElementsByTagName('base'), baseHref;
if(base.length && !myObject.sheet.cssRules){
for (var i = base.length - 1; i > -1; --i){
if(base[i].href){
baseHref = [i, base[i].href];
base[i].href = '#';
break;
}
}
}
myObject.sheet.cssRules[0].style.color = lastColor;
if(baseHref){
base[baseHref[0]].href = baseHref[1];
}
}
if (myObject.styleSheet) { myObject.styleSheet.rules[0].style.color = lastColor; } // IE style
}
Bookmarks