最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

Code:loadScript()加载js的功能函数_javascript技巧

来源:动视网 责编:小采 时间:2020-11-27 20:34:45
文档

Code:loadScript()加载js的功能函数_javascript技巧

Code:loadScript()加载js的功能函数_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 L
推荐度:
导读Code:loadScript()加载js的功能函数_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 L


代码如下:

/**
* 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
* 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);
}

实例:
代码如下:
// 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);

文档

Code:loadScript()加载js的功能函数_javascript技巧

Code:loadScript()加载js的功能函数_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 L
推荐度:
标签: js 函数 javascript
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top