×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: pery mimon
Added: Feb 16, 2017 2:19 PM
Modified: Feb 22, 2017 11:41 AM
Views: 10
Tags: no tags
  1. function loadStyle(cssFile){
  2.     var newlink = document.createElement("link");
  3.     newlink.setAttribute("rel", "stylesheet");
  4.     newlink.setAttribute("type", "text/css");
  5.     newlink.setAttribute("id", 'theme');
  6.     newlink.setAttribute("href", cssFile);
  7.  
  8.     document.head.appendChild(newlink);
  9. };
  10.  
  11. function loadStyle( cssFileURL ){
  12.     return new Promise(function (resolve,reject) {
  13.         var newlink = document.createElement("link");
  14.         newlink.setAttribute("rel", "stylesheet");
  15.         newlink.setAttribute("type", "text/css");
  16.         newlink.setAttribute("id", 'theme');
  17.         newlink.setAttribute("href", cssFileURL );
  18.  
  19.         newlink.addEventListener('load',resolve);
  20.         newlink.addEventListener('error',reject);
  21.  
  22.         document.head.appendChild(newlink);
  23.     });
  24.  
  25. }