javascript - Load CSS file based on URL parameter -


Can you help me to use javascript to load CSS files based on URL parameters?

I have 3 parameters (one, two and three) and I have 3 css files.

  if (window.location.search.search (/ [? & Amp;] parameter = one (?: $ | & Amp;; amp;) /)! == -1) {what code Should there go to load css? }  

Should JS be placed in the header of the HTML file?

  if (window.location.search.search (/ [? & Amp;] parameter = One (?: $ | & Amp;;;)) == -1) {var $ = document; // shortcut var cssId = 'myCss'; // You can encode the CSS path to generate IDs. If (! $ GetElementById (cssId)) {var head = $ .getElementsByTagName ('head') [0]; Var link = $ .createElement ('link'); Link.id = cssId; Link.rel = 'stylesheet'; Link.type = 'text / css'; Link.href = 'CSS / A CSS'; Link.media = 'all'; Head.appendChild (link); }} And if (window.location.search.search (/ [? & Amp;] parameter = two (?: $ | & Amp;))) == -1) {// Other method & amp; More simple var ss = document.createElement ("link"); Sstype = "text / css"; Ss.rel = "stylesheet"; Ss.href = "css / two.css"; Document.getElementsByTagName ("head") [0] .appendChild (ss); }  

and so on


Comments