* Most of the dynamic method to load js can be detect
* Once a js is loaded, the urlprotocal will not detect it any more. But the script will be run once more. Even if the script is altered, the web page won't load it any more.
* Take capture will not trigger url protocol
* Take photo:
native_urI will return the photo lib's path such as: "assets-library:\/\/asset\/asset.PNG?id=195E78F1-50CA-42A0-8D3E-D93171A61657&ext=PNG"
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
file_url will save to tempory dir, will trigger the urlprotocol, data_uri will return base64 data, will not trigger url protocol.
//************************************************************************************
Most of the time, Firefox, Safari and Opera work without much effort and differences between the 3. However, throw IE into the mix and you’re in a whole different world.This is helpful if you need to dynamically inject javascript.And, the biggest problem was setting a function that you want executed after the script is loaded.By this article I will provide 4 way to dynamically load external JavaScript.
choice 1. Using document.write
2 |
<script language= "javascript" >
|
3 |
document.write( "<script src='other.js'><\/script>" );
|
Can be detected;
choice 2.Dynamically change the src property value
1 |
<script src= '' id= "s1" ></script>
|
2 |
<script language= "javascript" >
|
3 |
document.getElementById("s1").src= "other.js"
|
Failed to load script without any error, not detect it
choice 3.Dynamically create <script> element
2 |
var oHead = document.getElementsByTagName( 'HEAD' ).item(0);
|
3 |
var oScript= document.createElement( "script" );
|
4 |
oScript.type = "text/javascript" ;
|
5 |
oScript.src= "other.js" ;
|
6 |
oHead.appendChild( oScript); |
Can be detected;
choice 4. Get JavaScript by using XMLHTTP,then create script object
1 |
<script language= "JavaScript" >
|
2 |
function GetHttpRequest()
|
4 |
if ( window.XMLHttpRequest )
|
5 |
return new XMLHttpRequest() ;
|
6 |
else if ( window.ActiveXObject )
|
7 |
return new ActiveXObject( "MsXml2.XmlHttp" ) ;
|
9 |
function AjaxPage(sId, url){
|
10 |
var oXmlHttp = GetHttpRequest() ;
|
11 |
oXmlHttp.OnReadyStateChange = function ()
|
13 |
if ( oXmlHttp.readyState == 4 )
|
15 |
if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 )
|
17 |
IncludeJS( sId, url, oXmlHttp.responseText ); |
21 |
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
|
25 |
oXmlHttp.open( 'GET' , url, true );
|
28 |
function IncludeJS(sId, fileUrl, source)
|
30 |
if ( ( source != null ) && ( !document.getElementById( sId ) ) ){
|
31 |
var oHead = document.getElementsByTagName( 'HEAD' ).item(0);
|
32 |
var oScript = document.createElement( "script" );
|
33 |
oScript.language = "javascript" ;
|
34 |
oScript.type = "text/javascript" ;
|
37 |
oScript.text = source; |
38 |
oHead.appendChild( oScript ); |
41 |
AjaxPage( "scrA" , "b.js" );
|
42 |
alert( "dynamically load javascript" );
|
43 |
alert( "dynamically load a.js and get the variable:" + str );
|
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState) { //IE
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function () {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function () {})
相关推荐
CSS&javascript动态网页设计与制作CSS&javascript动态网页设计与制作CSS&javascript动态网页设计与制作CSS&javascript动态网页设计与制作CSS&javascript动态网页设计与制作CSS&javascript动态网页设计与制作CSS&...
JSP&Servlet&JavaScript&Ajax&jQuery源代码
Learning PHP, MySQL & JavaScript, 5th Edition.epub
PHP, MySQL & JavaScript All-in-One For Dummies 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
ejb&&javascript-pdfejb&&javascript-pdfejb&&javascript-pdf
Learning PHP, MySQL & JavaScript With jQuery, CSS & HTML5(5th) 英文epub 第5版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Learning PHP MySQL & JavaScript(4th) 英文epub 第4版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
[CSS&javascript动态网页设计与制作].吴以欣.插图版
Learning.PHP.MySQL.&.JavaScript.4th.Edition.2014.12.pdf
完全掌握HTML&CSS&JAVASCRIPT,轻松应战!由日本人写的哦,汉化好了哦!
Jquery & CSS & Javascript CMH合集Jquery & CSS & Javascript CMH合集
Sams Teach Yourself PHP, MySQL & JavaScript All in One(6th) 英文azw3 第6版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
HTML && JavaScript 电子档课件ppt
详解HTML&CSS&JavaScript语法辞典
HTML&CSS&JavaScript词典范例,学习网页编程基本例子,适合初学者
DHTML&javascript 使用手册 动态 HTML (DHTML) 对象模型参考 DHTML 对象 DHTML 属性 DHTML 方法 DHTML 事件 DHTML 集合 HTML 参考 HTML 元素 HTML 字符集 样式表(CSS)参考 CSS 属性参考 CSS 长度单位参考...
2008ESRI中国区域用户大会资料集 Flex&JavaScript 2008ESRI中国区域用户大会资料集 Flex&JavaScript 2008ESRI中国区域用户大会资料集 Flex&JavaScript
even if you have only basic HTML knowledge. With this popular hands-on guide, you'll tackle dynamic web programming with the help of today's core technologies: PHP, MySQL, JavaScript, jQuery, CSS, ...
詳解HTML&CSS&JavaScript辞典
css&javascript小例子.可以好好看看