/**********************************************************

     说明:跨域请求数据Javascript组件
----------------------------------------------------------
add by OceanHo 2015-4-13 18:18:14
**********************************************************/
; (function (window, undefined) { var _ap = function () {
}, _asyncID = 2048, _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);
}; function delSc(id) {
var scripts = getSc();
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].attributes["id"]) {
if (parseInt(scripts[i].attributes["id"].value) === parseInt(id)) {
remove(scripts[i]);
}
}
}
}; function remove(script) {
if ((script) && (script.parentNode)) {
script.parentNode.removeChild(script);
}
}; function clearSc() {
var scripts = getSc();
for (var i = 0; i < scripts.length; i++) {
remove(scripts[i]);
}
}; function getSc() {
var s1 = [];
var scripts = window.document.getElementsByTagName("script");
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].attributes["async"]) {
if (scripts[i].attributes["async"].value === _asyncType) {
s1.push(scripts[i]);
}
}
}
return s1;
}; function createSc() { _asyncID++;
var script = window.document.createElement("script");
script.setAttribute("id", _asyncID);
script.setAttribute("async", _asyncType);
script.setAttribute("type", "text/javascript"); script.onload = script.onreadystatechange = function () { if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") { delSc(this.attributes["id"].value); 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, cbk, cb, param) {
if (!cb) cb = _cb;
if (!cbk) cbk = _cbKey;
var qs = this.map(',', param);
addSc(url, _cbKey + "=" + cb + "&" + qs);
}, getEasy: function (url, cb, param) {
if (!cb) cb = _cb;
var qs = this.map(',', param);
addSc(url, _cbKey + "=" + cb + "&" + qs);
}, getCustom: function (url, param) {
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 () { clearSc(); }
}; _ap.fn.init.prototype = _ap.fn; window.CrossLoad = _ap.fn.init(); })(window); // 使用 、
<script>
window.CrossLoad.getEasy("https://www.oceanho.com/common/chat/v2","ReciveMessageHandler",{}) function ReciveMessageHandler(msg){ }
</script>

script通过script标签跨域加载数据的更多相关文章

  1. jquery中ajax跨域加载

    今天学习ajax跨域加载,先来一段代码,异步加载的链接是爱奇艺的开源,我直接拿来用作测试 <!DOCTYPE html> <html lang="en"> ...

  2. jquery mobile 和phonegap开发总结之三跨域加载页面

    跨域加载 一要进行一定的配置见下面 $( document ).bind( "mobileinit", function() { // Make your jQuery Mobil ...

  3. RequireJS跨域加载html模版后被转成JS问题分析及解决

    问题描述 RequireJS跨域加载HTML模版失败,例如: 在a.com域名下请求CDN域名下的模版,text.js插件会把html文件转成html.js文件去加载,由于并没有生成html.js文件 ...

  4. chrome浏览器下用jQuery的load函数来跨域加载页面,响应状态status为(canceled)是什么情况? JSON和JSONP,也许你会豁然开朗,含jQuery用例

    http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html 问题来源:http://q.cnblogs.com ...

  5. JQuery和原生JS跨域加载JSON数据或HTML。

    前提:有时候需要在网页上,加载另一个网站上的数据.或者加载另一个网站上的一个页面.Js的Ajax请求不具备跨域功能,可以使用JQuery来实现. 网页端JS代码: $(function () { $. ...

  6. pdf.js跨域加载文件

    pdf.js一个基于Html的工具类,熟悉pdf.js的朋友们很清楚,pdf.js帮助我们做了很多事.尤其金融类网站会产生很多的报表.需要在线预览.pdf.js绝对是我们的首选 本地预览 在pdf.j ...

  7. flash 跨域加载 二次加载

    var url2:String = "http://thirdapp0.qlogo.cn/qzopenapp/fa5d80ebf9fc89aaa1d7ddb0e1b861e58d77b409 ...

  8. script标签跨域的缺点

    1,只支持GET,不支持其他例如:put,delete,post等 2,想拿到数据需要服务器端做出相应处理,必须在window域下面有对应的执行函数.例如:window.callbackHandler ...

  9. 使用script的src实现跨域和类似ajax效果

    在解决js的跨域问题的时候, 有多种方式, 其中有一种是利用script标签的src属性,因为这个属性是不受域名限制的,我们可以直接让src的这个链接指向跨域网站的一个接口, 这个接口返回的是js代码 ...

随机推荐

  1. April 17 2017 Week 16 Monday

    You will find that it is necessary to let things go; simply for the reason that they are heavy. 你会明白 ...

  2. 修改Windows下的Memcached下的服务端口

    在命令模式下,可以使用 memcached -p 12000 去指定端口,可服务安装后,却总是只有 -d runservice 的参数. 通过修改注册表来达到这个修改端口的目的. 在 HKEY_LOC ...

  3. Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.错误

    错误如图示: 1.在php的目录下建立个文件夹tmp,这个有权限的问题,如果是ntfs的分区,就一定要添加evryone的控制权限,否则是没用的.2.在php.ini找到session.save_pa ...

  4. 【洛谷4459】[BJOI2018] 双人猜数游戏(动态规划)

    点此看题面 大致题意: 一直有两个数\(m,n\),已知\(s\le m\le n\),且\(Alice\)和\(Bob\)二个"最强大佬"各知道\(mn\)和\(m+n\).每轮 ...

  5. Python实现接口测试中的常见四种Post请求数据

    前情: 在日常的接口测试工作中,模拟接口请求通常有两种方法, 利用工具来模拟,比如fiddler,postman,poster,soapUI等 利用代码来模拟,使用到一些网络模块,比如HttpClie ...

  6. Mybatis-generator自动生成

    第一步:导入架包 <build> <plugins> <plugin> <groupId>org.mybatis.generator</group ...

  7. 10分钟了解 代理模式与java中的动态代理

    前言    代理模式又分为静态代理与动态代理,其中动态代理是Java各大框架中运用的最为广泛的一种模式之一,下面就用简单的例子来说明静态代理与动态代理. 场景    李雷是一个唱片公司的大老板,很忙, ...

  8. jQuery 二级联动

    jQuery 二级联动 ----请选择省份---- 北京 上海 江苏 ----请选择城市---- 东城 西城 崇文 宣武 朝阳  黄浦 卢湾 徐汇 长宁 静安 南京  镇江 苏州 南通 扬州 & ...

  9. JS中的var、let、const

    1.var 在全局window中申明则为全局变量,是全局对象 window 的属性. var sum = 0 console.log(window.sum) console.log(sum); 在函数 ...

  10. Struts2基础学习2

    Struts2基础学习2 项目结构,测试页面与实体类 <%@ page language="java" contentType="text/html; charse ...