2017-09-04 6 views
0

私はあなたを助けてくれることを願っています。 ブラウザごとにCSSをロードする必要があります(chorme、safari、mozilla、ie)。 サファリオプションを追加するソリューションが見つかりましたが、それでも機能しません。ブラウザごとにCSSをロード

<script type="text/javascript"> 
var browser = navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ? 'chrome' : 'other'; 
    if (BrowserDetect.browser.indexOf("chrome")>-1) { 
document.write('<'+'link rel="stylesheet" href="/css/chrome.css" />'); 
} else if (BrowserDetect.browser.indexOf("mozilla")>-1) { 
    document.write('<'+'link rel="stylesheet" href="css/mozilla.css" />'); 
} else if (BrowserDetect.browser.indexOf("explorer")>-1) { 
    document.write('<'+'link rel="stylesheet" href="css/explorer.css" />'); 
} else if (BrowserDetect.browser.indexOf("safari")>-1) { 
    document.write('<'+'link rel="stylesheet" href="css/safari.css" />'); 
} 
</script> 

ページ上にHTML5オーディオプレーヤーがあり、各ブラウザにこのプレーヤーの色が変わるため、それぞれに異なる必要があります。

+0

にちょうどあなたのケースのための例を持っている意味ですか? – SaidbakR

+2

[Safari、Chrome、IE、Firefox、Operaブラウザの検出方法](https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera)の重複の可能性があります。 -browser) – ThePHPAddicted

答えて

2

Modernizr and Conditionizrをご覧ください。

理由:

  1. 彼らはあなたがホイールを再発明していない
  2. 良いのJavaScriptライブラリです。 DRY原則
  3. は彼らが更新されます、彼らはあなたがすべてのブラウザ

http://conditionizr.com/

https://modernizr.com/

の進化を追跡する必要はありませんので、私はこれを知っているすべての主要なブラウザの変化に適応します正確な答えではないと私はdownvotedすることができますが、私は行くべき最善の方法だと思う。今日はSafariバージョンで動作しますが、明日は失敗する可能性があります。あなたはそれがサファリを除くすべてのブラウザで動作することをconditionizrについては

あなたは

https://github.com/conditionizr/conditionizr/blob/master/docs/DOCS.md#basic-config-setup 
+1

これは最善の方法です! – ThePHPAddicted

関連する問題