Code:loadScript( )加載js的功能函數(shù)
更新時間:2007年02月02日 00:00:00 作者:
復制代碼 代碼如下:
<script type="text/javascript">
/**
* function loadScript
* Copyright (C) 2006 Dao Gottwald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Contact information:
* Dao Gottwald <dao at design-noir.de>
* Herltestra?e 12
* D-01307, Germany
*
* @version 1.5
* @url http://design-noir.de/webdev/JS/loadScript/
*/
function loadScript (url, callback) {
var script = document.createElement('script');
script.type = 'text/javascript';
/* should be application/javascript
* http://www.rfc-editor.org/rfc/rfc4329.txt
* http://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=84613
*/
if (callback)
script.onload = script.onreadystatechange = function() {
if (script.readyState && script.readyState != 'loaded' && script.readyState != 'complete')
return;
script.onreadystatechange = script.onload = null;
callback();
};
script.src = url;
document.getElementsByTagName('head')[0].appendChild (script);
}
</script>
實例:
復制代碼 代碼如下:
<script type="text/javascript">
// prevent google analytics from slowing down page loading
window.addEventListener ('load', function() {
loadScript ('http://www.google-analytics.com/urchin.js', function() {
window._uacct = 'UA-xxxxxx-x';
urchinTracker();
});
}, false);
</script>
// prevent google analytics from slowing down page loading
window.addEventListener ('load', function() {
loadScript ('http://www.google-analytics.com/urchin.js', function() {
window._uacct = 'UA-xxxxxx-x';
urchinTracker();
});
}, false);
</script>
相關(guān)文章
JS常見DOM節(jié)點操作示例【創(chuàng)建 ,插入,刪除,復制,查找】
這篇文章主要介紹了JS常見DOM節(jié)點操作,結(jié)合實例形式分析了JavaScript針對DOM節(jié)點的創(chuàng)建 ,插入,刪除,復制,查找等操作相關(guān)函數(shù)與使用技巧,需要的朋友可以參考下2018-05-05改變checkbox默認選中狀態(tài)及取值的實現(xiàn)代碼
下面小編就為大家?guī)硪黄淖僣heckbox默認選中狀態(tài)及取值的實現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05JS繪圖Flot如何實現(xiàn)動態(tài)可刷新曲線圖
這篇文章主要介紹了JS繪圖Flot如何實現(xiàn)動態(tài)可刷新曲線圖,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-10-10JavaScript用document.write()輸出換行的示例代碼
這篇文章主要介紹了JavaScript用document.write()輸出換行的示例代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11javascript實現(xiàn)網(wǎng)頁背景煙花效果的方法
這篇文章主要介紹了javascript實現(xiàn)網(wǎng)頁背景煙花效果的方法,涉及javascript數(shù)學運算及頁面元素動態(tài)操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08