Created
January 12, 2017 21:22
-
-
Save klihelp/499028199f852f407c5f54cb0f8f38ba to your computer and use it in GitHub Desktop.
Revisions
-
klihelp created this gist
Jan 12, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ /** * * @type is typescript * @td use better logic for every content load */ var loadJsURL = function(url) { var canJsLoad = function(url) { if (!url) return false; var scripts = document.getElementsByTagName('script'); for (var i = scripts.length; i--;) { // *td // better with substring or pos, thinking of // start if (scripts[i].src == url) return false; } return true; } // Load js url var insertJsUrl = function(url) { var script = document.createElement('script'); script.setAttribute('src', url); document.body.appendChild(script); } if ( canJsLoad(url) ) { insertJsUrl(url) } } // example // loadJsURL('www.website.com/embed.js')