Script tag implementation of JavaScript cross-domain solution

Source: Internet
Author: User

/********************************************************** Description: Cross-domain Request data JavaScript component----------------------------------------- -----------------add by  Dupe  2015-4-13 18:18:14******************************************** /;  (function  (window, undefined)  {    var _ap  = function  ()  {    }, _asyncid = 12349, _asynctype  =  "Asynctype", _version =  "1.5.0", _cbkey =  "CB",  _cb =   "";     function addsc (Url, cbandparam)  {         var script = createsc ();         script.setattribute ("src", url +  "?")  + cbandparam);         window.document.getelementsbytagname ( "Head") [0].appendchild (script);     };  &nBSP;&NBSP;FUNCTION&NBSP;DELSC (ID)  {        var scripts  =&NBSP;GETSC ();        for  (var i = 0; i  < scripts.length; i++)  {             if  (scripts[i].attributes["tb_id"])  {                 if  (parseint (scripts[i].attributes["tb_id"].value)  = == parseint (ID))  {                     remove (Scripts[i]);                 }             }        }    };     function remove (SCRIPT)  {        if  (script)  &&  ( Script.parentnode))  {             Script.parentNode.removeChild (script);        }    &NBSP;};&NBSP;&NBSP;&NBSP;&NBSP;FUNCTION&NBSP;CLEARSC ()  {         VAR&NBSP;SCRIPTS&NBSP;=&NBSP;GETSC ();        for  (var i  = 0; i < scripts.length; i++)  {             remove (Scripts[i]);        }  &NBSP;&NBSP;&NBSP;};&NBSP;&NBSP;&NBSP;&NBSP;FUNCTION&NBSP;GETSC ()  {         var s1 = [];        var scripts =  window.document.getelementsbytagname ("ScripT ");        for  (var i = 0; i <  scripts.length; i++)  {            if   (scripts[i].attributes["Tb_async"])  {                 if  (scripts[i].attributes["Tb_async"].value === _asynctype)  {                     s1.push (Scripts[i]);                 }            }         }        return s1;     };    function createsc ()  {         _asyncid++;        var script = window.document.createelement (" Script ");         script.setattribute (" tb_id ",  _asyncid);         script.setattribute ("Tb_async",  _asynctype);         script.setattribute ("type",  "Text/javascript");         script.onload = script.onreadystatechange = function  ()   {            if  (!this.readyState | |  this.readyState ===  "Loaded"  | |  this.readyState ===  "complete")  {                 //  join the waiting team. This tag object is removed after 2 seconds. Avoiding excessive cross-domain loading results in too many page script tags.                 //&nBsp;waitdel (this.attributes["tb_id"].value, 2000);          &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;DELSC (this.attributes["tb_id"].value);                 //  Resolve memory leak issues. ie6,7 seemingly invalid                  script.onload = script.onreadystatechange = null;             }        }         return script;    }    function  Waitdel (Id, interval)  {        window.setinterval (delSc (ID),  interval);     };    _ap.fn = _ap.prototype =  {        constructor: _ap,        version: _version,         init: function  (ARG)  {             return new _ap () .constructor;         },        get: function  (URL,&NBSP;CBK,&NBSP;CB,  param)  {            if  (!CB)   cb = _cb;            if  (!CBK)  cbk = _cbKey;            var  Qs = this.map (', ',  param);            &NBSP;ADDSC (url, _cbkey +  "="  + cb +  "&"  + qs);         },        geteasy: function  (url, cb,  param)  {            if  (!CB) &NBSP;CB  = _cb;            var qs =  this.map (', ',  param); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ADDSC ( url, _cbkey +  "="  + cb +  "&"  + qs);         },        getCustom: function  (URL,  param) &NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ADDSC (url,  This.map (', ',  param));        },         map: function  (Split, params)  {             var str, strs = [];             if  (typeof params !=  "string")  {                 params = eval (params);                 for  (var p in  params)  {                     strs.push (p +  "="  + params[p])                  }                 str = strs.join (split);             } else {                 str = param;             }            return str;         },        clear:  function  () &NBSP;{&NBSP;CLEARSC (); }    };    //  syntaxerror: expected expression, got  ') '     _ap.fn.init.prototype  = _ap.fn;    window. Tbap = _ap.fn.init ();}) (window);


This article is from the "idiot" blog, make sure to keep this source http://hotboy.blog.51cto.com/8826994/1632040

Script tag implementation of JavaScript cross-domain solution

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.