Home > Web Front-end > JS Tutorial > body text

Remote calling jquery.js in a js file will cause a strange problem under ie8_javascript skills

WBOY
Release: 2016-05-16 18:15:14
Original
908 people have browsed it
Copy code The code is as follows:

function include(path){
var a=document.createElement ("script");
a.type = "text/javascript";
a.src=path;
var head=document.getElementsByTagName("head")[0];
head .appendChild(a);
}
include("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js")

Like this You call the script under IE8. After pressing Enter in the IE8 address bar, there is no problem in calling jquery objects, methods, etc., but there will be problems after refreshing. After refreshing, you have to press Enter in the address bar no matter what.
There is no problem under Firefox. Attached is an html script of window.name, you can test it:
Copy the code The code is as follows:




Demo:Cross-domain
< ;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script> <br>function include(path){ <br>var a=document .createElement("script"); <br>a.type = "text/javascript"; <br>a.src=path; <br>//if (a.readStatus == 200) { <br>var head =document.getElementsByTagName("head")[0]; <br>head.appendChild(a); <br>//} <br>} <br>include("http://jqueryjs.googlecode.com/files /jquery-1.3.2.min.js") <br></script>
<script> <br>$(function(){ <br>function sendData(url, callback){ <br> if(!url || typeof url !== 'string'){ <br>return; <br>} <br>url = (url.indexOf('?') > 0 ? '&' : '?' ) 'windowname=true'; <br>var frame = $('<iframe style="display:none;"></iframe>').appendTo("body"); <br>var state = 0; <br>var clear = function(){ <br>try{ <br>frame[0].contentWindow.document.write('');//Clear the content of iframe <br>frame[0].contentWindow .close();//Avoid iframe memory leaks<br>frame.remove();//Delete iframe <br>}catch(e){} <br>}; <br>var getData = function(){ <br>try{ <br>var data = frame[0].contentWindow.name; <br>}catch(e){} <br>clear(); <br>if(callback && typeof callback === 'function '){ <br>callback(data); <br>} <br>}; <br>frame.bind('load', function(){ <br>if(state === 1){ <br> getData(); <br>} else if(state === 0){ <br>state = 1; <br>frame[0].contentWindow.location = "none.html"; <br>} <br> }); <br>frame[0].src = url; <br>} <br>//Application: <br>var testurl = 'http://www.jb51.cn/test.html'; <br>$("button").click(function(){ <br>sendData( testurl ,function(result){ <br>var fishDiv = $("#oldFish"); <br>fishDiv.html( "You get The data is: " result ); <br>}) <br>}) <br>}) <br></script>


< ;button>Load data remotely

Dev By < ;a href="http://www.jb51.cn" >Material download & Hua


Reference :Script Home




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template