是的,你可以使用JavaScript來做到這一點。
<script type="application/javascript">
if(navigator.userAgent.indexOf('Chrome') > -1)
{
document.write('<'+'link rel="stylesheet" href="css/myCssForChrome.css" />');
}else if(navigator.userAgent.indexOf('Firefox') > -1)
{
document.write('<'+'link rel="stylesheet" href="css/myCssForFirefox.css" />');
}else if(navigator.userAgent.indexOf('Safari') > -1)
{
document.write('<'+'link rel="stylesheet" href="css/myCssForSafari.css" />');
}else if(navigator.userAgent.toLowerCase().indexOf("op") > -1)
{
document.write('<'+'link rel="stylesheet" href="css/myCssForOpera.css" />');
} else {
document.write('<'+'link rel="stylesheet" href="css/myCssForIExplorer.css" />');
}
</script>
而不是用戶代理從文檔中獲取域路徑並檢查您想要更改CSS的唯一域。
謝謝!這不會僅僅將樣式表應用於當前文檔嗎?我需要一個頁面,並將其應用於a.html和b.html,而不在b.html中嵌入任何內容。 – Skettenring
只需將該腳本放在文件中並加載到兩側,頂部或底部,或者當您的window.load –