将A标签的href用iframe打开(JS)
修改后的。。
Code
1 ///<reference path="jquery-1.2.6-vsdoc-cn.js" />
2 /*
3 *这个JS文件的作用是将A标签的href用iframe打开
4 * 2009年7月17日
5 * zzjj296
6 */
7 $(document).ready(function(){
8 $(".zMode").each(
9 function(index,obj){
10 obj.onclick=function(){
11 _zModeFn(obj.href2 ,obj.zWidth);
12 }
13 }
14 )
15 }
16 );
17 function _zModeFn(Url,Width){
18 var url="http://www.baidu.com/";
19 var width=780;
20 var imgPath="../images/close.gif";
21 if(Url!=null){url=Url;}
22 if(Width!=null){width=parseInt(Width);}
23
24 var div = document.createElement("div");
25 with(div.style)
26 {
27 border="1 solid #999";
28 left=0;
29 top=0;
30 position="absolute";
31 filter="alpha(opacity=80)";
32 backgroundColor="#000";
33 zIndex=1;
34 }
35 div.style.height=800>document.body.scrollHeight?800:document.body.scrollHeight;
36
37 div.style.width=document.body.scrollWidth;
38
39 document.body.appendChild(div);
40
41 var div2=document.createElement("div");
42 with(div2.style)
43 {
44 border="4 solid #777777";
45 position="absolute";
46 zIndex=2;
47 }
48 div2.style.width=width;
49 div2.style.height=100;
50 div2.style.top=30;
51
52 div2.style.left=20;
53 document.body.appendChild(div2);
54
55 var f1=document.createElement("iframe");
56 f1.src=url;
57 f1.width=parseInt(div2.style.width)-8;
58 var IntervalId = window.setInterval(
59 function(){
60 reinitIframe(div2,f1);
61 }
62 , 200);
63 div2.appendChild(f1);
64
65 var divClose=document.createElement("div");
66 with(divClose.style)
67 {
68 width=12;
69 height=12;
70 position="absolute";
71 backgroundImage="url("+imgPath+")";
72 fontSize="5px";
73 lineHeight="5px";
74
75 top=parseInt(div2.style.top)-6;
76 left=parseInt(div2.style.left) + parseInt(div2.style.width)-4;
77 zIndex=3;
78 }
79 document.body.appendChild(divClose);
80
81 divClose.onclick=function(){
82 //销毁
83 window.clearInterval(IntervalId);//自动高度
84 div.parentNode.removeChild(div);
85 div2.parentNode.removeChild(div2);
86 divClose.parentNode.removeChild(divClose);
87 }
88 }
89
90 function reinitIframe(obj,iframe){
91
92 try{
93 var bHeight = iframe.contentWindow.document.body.scrollHeight;
94 var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
95 var height = Math.max(bHeight, dHeight);
96 iframe.height = height;
97 obj.style.height=height;
98 }catch (ex){alert(ex.message);}
99 }
100
1 ///<reference path="jquery-1.2.6-vsdoc-cn.js" />
2 /*
3 *这个JS文件的作用是将A标签的href用iframe打开
4 * 2009年7月17日
5 * zzjj296
6 */
7 $(document).ready(function(){
8 $(".zMode").each(
9 function(index,obj){
10 obj.onclick=function(){
11 _zModeFn(obj.href2 ,obj.zWidth);
12 }
13 }
14 )
15 }
16 );
17 function _zModeFn(Url,Width){
18 var url="http://www.baidu.com/";
19 var width=780;
20 var imgPath="../images/close.gif";
21 if(Url!=null){url=Url;}
22 if(Width!=null){width=parseInt(Width);}
23
24 var div = document.createElement("div");
25 with(div.style)
26 {
27 border="1 solid #999";
28 left=0;
29 top=0;
30 position="absolute";
31 filter="alpha(opacity=80)";
32 backgroundColor="#000";
33 zIndex=1;
34 }
35 div.style.height=800>document.body.scrollHeight?800:document.body.scrollHeight;
36
37 div.style.width=document.body.scrollWidth;
38
39 document.body.appendChild(div);
40
41 var div2=document.createElement("div");
42 with(div2.style)
43 {
44 border="4 solid #777777";
45 position="absolute";
46 zIndex=2;
47 }
48 div2.style.width=width;
49 div2.style.height=100;
50 div2.style.top=30;
51
52 div2.style.left=20;
53 document.body.appendChild(div2);
54
55 var f1=document.createElement("iframe");
56 f1.src=url;
57 f1.width=parseInt(div2.style.width)-8;
58 var IntervalId = window.setInterval(
59 function(){
60 reinitIframe(div2,f1);
61 }
62 , 200);
63 div2.appendChild(f1);
64
65 var divClose=document.createElement("div");
66 with(divClose.style)
67 {
68 width=12;
69 height=12;
70 position="absolute";
71 backgroundImage="url("+imgPath+")";
72 fontSize="5px";
73 lineHeight="5px";
74
75 top=parseInt(div2.style.top)-6;
76 left=parseInt(div2.style.left) + parseInt(div2.style.width)-4;
77 zIndex=3;
78 }
79 document.body.appendChild(divClose);
80
81 divClose.onclick=function(){
82 //销毁
83 window.clearInterval(IntervalId);//自动高度
84 div.parentNode.removeChild(div);
85 div2.parentNode.removeChild(div2);
86 divClose.parentNode.removeChild(divClose);
87 }
88 }
89
90 function reinitIframe(obj,iframe){
91
92 try{
93 var bHeight = iframe.contentWindow.document.body.scrollHeight;
94 var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
95 var height = Math.max(bHeight, dHeight);
96 iframe.height = height;
97 obj.style.height=height;
98 }catch (ex){alert(ex.message);}
99 }
100
下载地址:zMode.rar