Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. // this will work in IE 10, 11 and Safari/Chrome/Firefox/Edge
  2. // add ES6 poly-fill for the Promise, if needed (or rewrite to use a callback)
  3.  
  4. let fetchStyle = function(url) {
  5. return new Promise((resolve, reject) => {
  6. let link = document.createElement('link');
  7. link.type = 'text/css';
  8. link.rel = 'stylesheet';
  9. link.onload = function() { resolve(); console.log('style has loaded'); };
  10. link.href = url;
  11.  
  12. let headScript = document.querySelector('script');
  13. headScript.parentNode.insertBefore(link, headScript);
  14. });
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement