我正在使用以下代碼片段以非阻塞方式異步加載JavaScript。它適用於Chrome,FF但無法在Internet Explorer中使用。匿名函數在Internet Explorer中無效
我正在運行IE8,並且無法在IE中爲以下代碼命中onload函數;
<script type="text/javascript">
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'js/load_outer.js';
s.onload = function() {
alert("Loaded");
}
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
})();
</script>
任何人都可以幫我找出錯誤嗎?
感謝
您可能會或可能不會得到一個 「load」 事件時,腳本加載在IE中。 – Pointy 2012-02-24 12:34:31
這裏有一個相關的問題:[http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer](http://stackoverflow.com/questions/4845762/onload-處理器換腳本標籤在互聯網資源管理器)。 – jabclab 2012-02-24 12:35:07
@jakeclarkson感謝您的鏈接。但是,我不得不避免使用任何第三方庫 – Jayesh 2012-02-24 12:37:32