1、XHR Injectionjavascript
使用動態建立script元素,來寫入腳本html
例如java
var xhrObj = new XMLHttpRequest(); xhrObj.onreadystatechange = function(){ if(xhrObj.readyState == 4){ var scriptElem = document.createElement("script"); document.getElementsByTagName("head")[0].appendChild(scriptElem); scriptElem.text = xhrObj.responseText; } }; xhrObj.open("GET", "A.js", true); xhrObj.send("");
2、Script DOM Element跨域
利用動態插入script元素來讓腳本讀取、生效,此方式支持跨域app
例如code
var scriptElem = document.createElement("script"); scriptElem.src = "A.js"; document.getElementByTagName("head")[0].appendChild(scriptElem);
參考資料:JavaScript無阻塞加載經常使用的方法 http://www.studyofnet.com/news/1245.htmlhtm