JavaScript Hack to re-enable alternate stylesheets for Safari 5.1 9.10.2011
JavaScript Hack to re-enable alternate stylesheets for Safari 5.1 9.10.2011
Am So 09.10.2011
Safari never had a menu for "alternate stylesheets" of a web-page. But you can enable and disable stylesheets via JavaScript by setting the attribute "disabled". This worked on all browsers - till now. Safari 5.1 doesn't react on "disabled" any more.
I wrote a small hack to reactivate the JavaScript funktionality to use alternate stylesheets. This is a variation of a widely used JavaScrip funktion. I hope this remains a temporary hack and Safari will work in the standard way again.
function setActiveStyleSheet(title) { // detect Safari 5.1, which doesn't handle Alternate StyleSheets property "disabled" status: 2011.10.09 var IstFaultySafari = RegExp("Version/5.1 Safari").test(navigator.userAgent); if (IstFaultySafari && console && window.console.log) console.log("Faulty Safari 5.1 which has problems with alternate stylesheet"); var titleBU; var i, a; for (i=0; (a=document.getElementsByTagName('link')[i]); i++) { if ( a.getAttribute('rel').indexOf('style') != -1 && ( a.getAttribute('title') || a.getAttribute('data-title') ) ) { // disable all alternate stylesheets a.disabled = true; if (IstFaultySafari){ titleBU = a.getAttribute("data-title"); if (titleBU) { a.setAttribute("rel","alternate stylesheet"); a.setAttribute("title",titleBU); } } if(a.getAttribute('title') == title) { a.disabled = false; if (IstFaultySafari){ a.setAttribute("rel","stylesheet"); a.setAttribute("data-title",title); a.removeAttribute("title"); } } } } }(Excuse the bad formatting of the code, my system automatically optimizes the text-flow for human-readable text, removes "ASCII-art". I have to do a code-setup too.)
Diesen Artikel verlinken: http://acommunity.at/A/klat - Artikel empfehlen: Tweet