Remotely calling jquery. js in a js file will cause a strange problem in ie8.

Source: Internet
Author: User

Copy codeThe 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 ();
}
Include ("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js ")

You can call this script in ie8, press enter in the address bar of ie8, and then call jquery's object and method. However, there is a problem after refreshing. After refreshing, press enter in the address bar.
There is no problem under Firefox. The following is an html Script For window. name. You can test it:Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Demo: Cross-origin </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Script>
Function include (path ){
Var a = document. createElement ("script ");
A. type = "text/javascript ";
A. src = path;
// If (a. readStatus = 200 ){
Var head = document. getElementsByTagName ("head") [0];
Head. appendChild ();
//}
}
Include ("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js ")
</Script>
<Script>
$ (Function (){
Function sendData (url, callback ){
If (! Url | typeof url! = 'String '){
Return;
}
Url + = (url. indexOf ('? ')> 0? '&':'? ') + 'Windowname = true ';
Var frame = $ ('<iframe style = "display: none;"> </iframe>'). appendTo ("body ");
Var state = 0;
Var clear = function (){
Try {
Framework0).contentdomaindoc ument. write (''); // clear iframe content
Frame [0]. contentWindow. close (); // prevent iframe Memory leakage
Frame. remove (); // Delete iframe
} Catch (e ){}
};
Var getData = function (){
Try {
Var data = frame [0]. contentWindow. name;
} Catch (e ){}
Clear ();
If (callback & typeof callback === 'function '){
Callback (data );
}
};
Frame. bind ('load', function (){
If (state = 1 ){
GetData ();
} Else if (state = 0 ){
State = 1;
Frame [0]. contentWindow. location = "none.html ";
}
});
Frame [0]. src = url;
}
// Application:
Var testurl = 'HTTP: // www.jb51.cn/test.html ';
$ ("Button"). click (function (){
SendData (testurl, function (result ){
Var fishDiv =$ ("# oldFish ");
FishDiv.html ("the data you obtained is:" + result );
})
})
})
</Script>
</Head>
<Body>
<Button> remotely load data </button>
<Div id = "oldFish"> </div>
<P style = "font-size: 12px;"> Dev By <a href = "http://www.jb51.cn"> material download </a> & Hua </p>
<P style = "font-size: 12px;"> reference: <a href = "http://www.jb51.net"> feet home </a> </p>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.