当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Code:loadScript( )加载js的功能函数

Javascript
一定时间滚动的链接菜单效果
超链接的陷下效果
用js实现的打字效果的带链接的新闻标题
js实现的很酷的连接提示效果
再谈IE中Flash控件的自动激活 ObjectWrap
超级兔子让浮动层消失的前因后果
在线编辑器的实现原理(兼容IE和FireFox)
B/S开发中常用javaScript技术与代码
用JavaScript事件串连执行多个处理过程的方法
Javascript中的Split使用方法与技巧
HTML在线编辑器的基本概念与相关资料
Js+DVML很酷漂亮实用的右键弹出菜单
用js实现的比较经典实用的触发型导航菜单
js中slice()方法的使用说明
基础的prototype.js常用函数及其用法
常用限制input的方法的js代码
又一个图片自动缩小的JS代码
JavaScript触发器详解
理解Javascript的caller,callee,call,apply区别
一个简单的日历代码 (For: FF1+ IE5+ Opr7+)测试

Javascript 中的 Code:loadScript( )加载js的功能函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 256 ::
收藏到网摘: n/a

复制代码 代码如下:

<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>