职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 425|回复: 1

关于iframe 以及节点的一些操作 头痛

[复制链接]
fl 发表于 2011-8-29 09:36 | 显示全部楼层 |阅读模式
*只是研究 与工作无关
  
function af(){   
  this.isrd=false;   
  this.height=100;   
  this.width=100;   
  this.html='';   
  if(window.self==window.top){   
    this.isrd=true;   
    this.cpage();   
    this.CreatIfr();   
  }   
}   
af.prototype.right=function(str,n){   
  return str.substr(str.length-n,str.length);   
};   
af.prototype.Dbody=function(){   
  var bHeight=document.body.clientHeight;   
  var dHeight=document.documentElement.clientHeight;   
  var isXhtml=(dHeight<=bHeight&&dHeight!==0)?true:false;   
  var sDbody=isXhtml?document.documentElement:document.body;   
  return sDbody;   
};   
af.prototype.surl=function(){   
  var nowurl=location.href;   
  nowurl+=(location.search)?"&":"?";   
  nowurl+="iris";   
  return nowurl;   
};   
af.prototype.cpage=function(){   
  this.Dbody().style.overflow="hidden";   
  document.body.innerhtml="";   
};   
af.prototype.CreatIfr=function(){   
  var iriscontent1=document.createElement("div");   
  iriscontent1.id="ifr";   
  iriscontent1.style.height="100%";   
  iriscontent1.style.overflow="hidden";   
  document.body.appendChild(iriscontent1);   
     
  var iriscontent=document.createElement("iframe");   
  iriscontent.src=this.surl();   
  iriscontent.id="ifr2";   
  iriscontent.name="ifr2";   
  iriscontent.width="100%";   
  iriscontent.height="100%";   
  iriscontent.style.position="absolute";   
  iriscontent.style.right="0";   
  iriscontent.style.bottom="0";   
  iriscontent.style.overflow="hidden";   
  iriscontent.setAttribute("frameborder","0",0);   
  iriscontent.setAttribute("scrolling","no");   
  document.getElementById("ifr").appendChild(iriscontent);   
};   
  
af.prototype.setwindow=function(){   
  if(!this.isrd){   
    return ;   
  }   
  var tempw=this.width;   
  var audiocontent=document.createElement("div");   
  audiocontent.id="mpl";   
  audiocontent.style.height=this.height+"px";   
  if(this.right(tempw,1)!="%"){   
    tempw+="px";   
  }   
  audiocontent.style.width=tempw;   
  audiocontent.innerHTML=this.html;   
  audiocontent.style.position="absolute";   
  audiocontent.style.right="20px";   
  audiocontent.style.bottom="0";   
  document.body.appendChild(audiocontent);   
  this.settop(this.height);   
};   
af.prototype.settop=function(sh){   
  if(!this.isrd){   
    return ;   
  }   
};   
af.prototype.AutoIframe=function(){   
  if(!this.isrd){   
    return ;   
  }   
  var removewrap=document.getElementById("iris");   
  if(removewrap!==null){   
    removewrap.parentNode.removeChild(removewrap);   
  }   
};   
/////////////   
var init = new af();   
init.html = '123';   
  
init.setwindow();   
window.setInterval("init.AutoIframe()", 200);  

function af(){
  this.isrd=false;
  this.height=100;
  this.width=100;
  this.html='';
  if(window.self==window.top){
    this.isrd=true;
    this.cpage();
    this.CreatIfr();
  }
}
af.prototype.right=function(str,n){
  return str.substr(str.length-n,str.length);
};
af.prototype.Dbody=function(){
  var bHeight=document.body.clientHeight;
  var dHeight=document.documentElement.clientHeight;
  var isXhtml=(dHeight<=bHeight&&dHeight!==0)?true:false;
  var sDbody=isXhtml?document.documentElement:document.body;
  return sDbody;
};
af.prototype.surl=function(){
  var nowurl=location.href;
  nowurl+=(location.search)?"&":"?";
  nowurl+="iris";
  return nowurl;
};
af.prototype.cpage=function(){
  this.Dbody().style.overflow="hidden";
  document.body.innerhtml="";
};
af.prototype.CreatIfr=function(){
  var iriscontent1=document.createElement("div");
  iriscontent1.id="ifr";
  iriscontent1.style.height="100%";
  iriscontent1.style.overflow="hidden";
  document.body.appendChild(iriscontent1);
  
  var iriscontent=document.createElement("iframe");
  iriscontent.src=this.surl();
  iriscontent.id="ifr2";
  iriscontent.name="ifr2";
  iriscontent.width="100%";
  iriscontent.height="100%";
  iriscontent.style.position="absolute";
  iriscontent.style.right="0";
  iriscontent.style.bottom="0";
  iriscontent.style.overflow="hidden";
  iriscontent.setAttribute("frameborder","0",0);
  iriscontent.setAttribute("scrolling","no");
  document.getElementById("ifr").appendChild(iriscontent);
};

af.prototype.setwindow=function(){
  if(!this.isrd){
    return ;
  }
  var tempw=this.width;
  var audiocontent=document.createElement("div");
  audiocontent.id="mpl";
  audiocontent.style.height=this.height+"px";
  if(this.right(tempw,1)!="%"){
    tempw+="px";
  }
  audiocontent.style.width=tempw;
  audiocontent.innerHTML=this.html;
  audiocontent.style.position="absolute";
  audiocontent.style.right="20px";
  audiocontent.style.bottom="0";
  document.body.appendChild(audiocontent);
  this.settop(this.height);
};
af.prototype.settop=function(sh){
  if(!this.isrd){
    return ;
  }
};
af.prototype.AutoIframe=function(){
  if(!this.isrd){
    return ;
  }
  var removewrap=document.getElementById("iris");
  if(removewrap!==null){
    removewrap.parentNode.removeChild(removewrap);
  }
};
/////////////
var init = new af();
init.html = '123';

init.setwindow();
window.setInterval("init.AutoIframe()", 200);



这段代码作用是
将当前页装入一个动态生成的iframe

再在这个iframe之外创建一个层 用于定义其他内容

并将原文档中父节点 #iris删除


文档初始结构

<body>
<div id='iris'>
...............
</div>
</body>

应用脚本后的结构 因该是这样
<body>
<div id='ifr'>

<iframe id='ifr2'>
  <body>
    <div id='iris'>
    ...............
    </div>
  </body>
</iframe>

</div>

</body>

从最初构思 到写成 一个补丁+一个补丁这样七拼八凑 还是功底太薄了 不能一气呵成
朋友们能不能够帮我重构一下

叫我小乖 发表于 2011-8-29 09:37 | 显示全部楼层
推荐链接

见证又一个准百万富翁的诞生!
20-30万急聘多名天才Java/MTA软件工程师
3G培训就业月薪平均7K+,不3K就业不花一分钱!

您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-4-27 04:04 , Processed in 0.130127 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表