麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > JS > 正文

How to Auto Include a Javascript File

2024-09-06 12:43:31
字體:
供稿:網(wǎng)友
Form: http://www.webreference.com/programming/javascript/mk/
Author:Mark Kahn

Many developers have a large library of JavaScript code at their fingertips that they developed, their collegues developed, or that they've pieced together from scripts all over the Internet. Have you ever thought that it would be nice to not have to search through all those files just to find that one function? This article will show you how dynamically include any JavaScript file, at runtime, by simply calling a function in that file!

Here's an example: You have a function foo() in file bar.js. In your code, you know that foo() might be called, but it probably won't be because most people do not use its functionality. You don't want to force the user to download bar.js unless it's going to be used because it's a fairly large file. Here you'll learn how to make a fake foo() function that actually loads bar.js on the fly and then calls the real foo() function.

Dynamically Loading a Script
As many developers know, there are at least two different ways to dynamically load a script at runtime. The first is to create a script object and append it to the document. The second is to use an XMLHTTP request to grab the source code, and then eval() it. 

It is this second method that we're going to use, and we're going to exploit the fact that an XMLHTTP request has the capability to completely stall any script activity. 

First, some basics: how to create an XMLHTTP Object. There are as many different functions to return a cross-browser XMLHTTP Object as there are developers that work with AJAX. I happen to have my own as well, and here's a simplified example of that: 
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 性生活香蕉视频 | 91 久久| 黄色毛片18 | 黄色免费av| 久久久在线免费观看 | 亚洲第一成人av | 国产精品亚洲精品日韩已方 | 看毛片电影 | 亚洲自拍第二页 | chengrenyingshi| 成人福利在线视频 | 欧美日韩国产成人在线 | 久产久精品 | 欧美色大成网站www永久男同 | 一级毛片真人免费播放视频 | 久久视讯| 91精品福利视频 | 久久国产精品久久久久久电车 | 国产精品99一区二区 | 国产精品久久久久久久久久三级 | 激情网站视频 | 免费人成在线播放 | 免费男女视频 | 巨根插入 | 久久影城| 最新91在线视频 | 国产91小视频在线观看 | 88xx成人精品视频 | 黄色的视频免费看 | 午夜精品视频免费观看 | 国产一国产一级毛片视频在线 | 99999久久久久久 | 视频一区二区中文字幕 | 国产精品久久久久久久av三级 | 黄色片快播 | 成人羞羞国产免费游戏 | 激情网站免费观看 | 国产午夜免费福利 | 日韩黄色在线播放 | 久久综合一区 | 92精品国产自产在线 |