我想動態地包括一個腳本標籤在網頁上,但我沒有控制它的src所以src =「source.js」可能看起來像這樣。動態添加腳本標籤與src,可能包括document.write
document.write('<script type="text/javascript">')
document.write('alert("hello world")')
document.write('</script>')
document.write('<p>goodbye world</p>')
現在通常把
<script type="text/javascript" src="source.js"></script>
在頭工作正常,但是否有其他辦法,我可以添加動態地使用類似的innerHTML source.js?
經過數小時的苦苦掙扎後,解決方案是! [https://github.com/krux/postscribe/](https://github.com/krux/postscribe/) –
[async loading with document.write]可能出現重複(http://stackoverflow.com/ questions/13003644/async-loading-javascript-with-document-write) –