Hypertext
07-09-2008, 05:35 PM
To add a css file for opera and safari, I'm using this code I found:
function isSaf() {
return = (document.childNodes && !document.all && !navigator.taintEnabled && !navigator.accentColorName) ? true : false;
}
function isOp() {
return (window.opera) ? true : false;
}
function loadPatches(dir) {
if (document.getElementsByTagName() && document.createElement()) {
var head = document.getElementsByTagName("head")[0];
if (head) {
var css = new Array();
if (isSaf()) {
css.push("saf.css");
} else if (isOp()) {
css.push("opera.css");
}
if (css.length) {
var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("media", "screen, projection");
for (var i = 0; i < css.length; i++) {
var tag = link.cloneNode(true);
tag.setAttribute("href", dir + css[0]);
head.appendChild(tag);
}
}
}
}
}
$(document).ready(function() {
loadPatches('css/')
});
With a bit of editing I got it working, but for some strange reason, It's not liking the opera detection, safari detection works, but opera doesn't, I've used firebug to detect whether it has been written to the document and it hasn't. Any ideas?
function isSaf() {
return = (document.childNodes && !document.all && !navigator.taintEnabled && !navigator.accentColorName) ? true : false;
}
function isOp() {
return (window.opera) ? true : false;
}
function loadPatches(dir) {
if (document.getElementsByTagName() && document.createElement()) {
var head = document.getElementsByTagName("head")[0];
if (head) {
var css = new Array();
if (isSaf()) {
css.push("saf.css");
} else if (isOp()) {
css.push("opera.css");
}
if (css.length) {
var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("media", "screen, projection");
for (var i = 0; i < css.length; i++) {
var tag = link.cloneNode(true);
tag.setAttribute("href", dir + css[0]);
head.appendChild(tag);
}
}
}
}
}
$(document).ready(function() {
loadPatches('css/')
});
With a bit of editing I got it working, but for some strange reason, It's not liking the opera detection, safari detection works, but opera doesn't, I've used firebug to detect whether it has been written to the document and it hasn't. Any ideas?