Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Look at these functions:</p> <pre><code>$.ajax({ url:'CSS URL HERE', type:'HEAD', error: function() { AddLocalCss(); }, success: function() { //file exists } }); </code></pre> <p>And here is vanilla JavaScript version: </p> <pre><code>function UrlExists(url) { var http = new XMLHttpRequest(); http.open('HEAD', url, false); http.send(); return http.status!=404; } if (!UrlExists('CSS URL HERE') { AddLocalCss(); } </code></pre> <p>Now the actual function:</p> <pre><code>function AddLocalCss(){ document.write('&lt;link rel="stylesheet" type="text/css" href=" LOCAL CSS URL HERE"&gt;') } </code></pre> <p>Just make sure AddLocalCss is called in the head.</p> <p>You might also consider using one of the following ways <a href="https://stackoverflow.com/questions/805384/how-to-apply-inline-and-or-external-css-loaded-dynamically-with-jquery/805406#805406">explained in this answer</a>:</p> <p>Load using AJAX</p> <pre><code>$.get(myStylesLocation, function(css) { $('&lt;style type="text/css"&gt;&lt;/style&gt;') .html(css) .appendTo("head"); }); </code></pre> <p>Load using dynamically-created </p> <pre><code>$('&lt;link rel="stylesheet" type="text/css" href="'+myStylesLocation+'" &gt;') .appendTo("head"); Load using dynamically-created &lt;style&gt; $('&lt;style type="text/css"&gt;&lt;/style&gt;') .html('@import url("' + myStylesLocation + '")') .appendTo("head"); </code></pre> <p>or</p> <pre><code>$('&lt;style type="text/css"&gt;@import url("' + myStylesLocation + '")&lt;/style&gt;') .appendTo("head"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload