怎樣動態地插入不會暴露給用戶的JS文件

也是無心間看見的,之前想過這個問題,可是沒多想,今天看到這段代碼豁然開朗javascript

(function() {
    var dynamicScript = document.createElement('script'); 
    dynamicScript.type = 'text/javascript'; 
    dynamicScript.async = true;
    dynamicScript.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.xxx.com/dynamicScript.js';
    var firstScript = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(dynamicScript, firstScript);
})();
相關文章
相關標籤/搜索