您的位置:首页 > 其它

基本文本处理---学习笔记

2013-04-25 13:31 357 查看
function CrossDomainName(target, agent, callback, security) {
if (typeof target !== 'string' || typeof agent !== 'string' || typeof callback !== 'function') {
throw '参数错误';
}
this.state = 0;
this.target = target;
this.agent = agent;
this.callback = callback || Function;
this.security = security || true;
this.iframe = document.createElement('iframe');
var self = this;
function onload() {
if (self.state === 1) {
var data = self.iframe.contentWindow.name;
self.callback.call(self.iframe, data);
if (self) {
self.iframe.contentWindow.document.close();//关闭文档流
self.iframe.contentWindow.close();//关闭Iframe
document.body.removeChild(self.iframe);//移除Iframe
}
} else if (self.state === 0) {
self.state = 1;
self.iframe.contentWindow.location = self.agent;
}
}
if (document.attachEvent) {
this.iframe.attachEvent('onload', onload);
} else if (document.addEventListener) {
this.iframe.addEventListener('load', onload, false);
} else {
this.iframe.onload = onload;
}
this.iframe.src = this.target;
document.body.appendChild(this.iframe);
}
//调用
new CrossDomainName('http://www.kingwell.com/kingwell.html', 'http://name.b.com/adfas.html', function (data) {
alert(data);
});

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: