Code:loadScript( )加載js的功能函數(shù)
更新時間:2007年02月02日 00:00:00 作者:
復(fù)制代碼 代碼如下:
<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>
實例:
復(fù)制代碼 代碼如下:
<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)文章
javascript實現(xiàn)用戶點擊數(shù)量統(tǒng)計
本文主要javascript實現(xiàn)用戶點擊數(shù)量統(tǒng)計的方法進行詳細(xì)介紹,具有很好的參考價值,需要的朋友一起來看下吧2016-12-12
js學(xué)習(xí)總結(jié)之DOM2兼容處理順序問題的解決方法
這篇文章主要為大家詳細(xì)介紹了DOM2兼容處理順序問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
Web開發(fā)中使用SVG圖標(biāo)的7種方法舉例總結(jié)
這篇文章主要介紹了7種嵌入SVG圖標(biāo)的方法,包括內(nèi)聯(lián)SVG、img標(biāo)簽、object標(biāo)簽、CSS背景圖像、SVG圖標(biāo)字體、use元素和JavaScript動態(tài)加載,每種方法都有其優(yōu)勢和限制,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-03-03
JavaScript實現(xiàn)MD5加密的六種方式實例
這篇文章主要給大家介紹了關(guān)于JavaScript實現(xiàn)MD5加密的六種方式,在JS中可以實現(xiàn)MD5加密算法,可以使用第三方庫或者自己編寫代碼實現(xiàn),需要的朋友可以參考下2023-09-09
用JavaScript 處理 URL 的兩個函數(shù)代碼
用JavaScript 處理 URL 的兩個函數(shù)代碼...2007-08-08

