css|脚本
判断客户端浏览器载入样式表
if (browser.isNS4x == true) {
document.write('<link rel="stylesheet" type="text/css" href="ns4.css">');
}
else {
document.write('<link rel="stylesheet" type="text/css" href="advanced.css">');
}
判断客户端浏览器控制页面样式
if (browser.isNS4x == true) {
// Tag selectors
document.tags.body.fontSize = '11px';
document.tags.td.fontSize = '11px';
document.tags.th.fontSize = '11px';
document.tags.p.fontSize = '11px';
// Class selectors
document.classes.someClass.all.fontSize = '11px';
// Id selectors
document.ids.someId.fontSize = '11px';
}
Using the DOM
The best way to work with CSS from Javascript is to use the DOM. You can disable or remove existing stylesheets, add new stylesheets, make existing <link> tags point to different .css files, add or remove rules, add or remove declarations, change classes or styles on existing elements, whatever you like. But there is a catch: the browsers you want to manipulate styles for must support the DOM methods needed to do the manipulation you want. So instead of doing browser detection, it would be better to do object detection on the DOM objects you want to manipulate. The DOM is a huge topic and I'm not going to tackle it here. Instead, I direct readers to an article on Manipulating CSS using the W3C DOM and Peter-Paul Koch's DOM Compatibility Chart for CSS.
Referrence
CSS filtering using Javascript http://www.dithered.com/css_filters/js_summary.html