无边框窗口代码详解

/*代码思路
此代码会以fullscreen方式打开一个空白窗口,然后用window.resize改变其大小。
最后在以写入onload="location.replace='url'"的办法将网址改变。
打开的窗口会是一个带有FRAME的窗口,其中窗口顶端会有一个高22的框架网页。
此网页是用来操纵窗口移动及关闭。
*/

/*说明
代码分两个部分,但总共牵涉到5个HTML文件及4个图像文件
第一部分是用来打开窗口,放在哪个文件都无所谓。
第二部分是用来控制窗口的移动及关闭,必须放在指定的文件里。
在此代码里,5个html文件分别为:
1.html; 代码第一部分所在
load.html; 所打开的窗口,是一个框架网页
chromelesstit.html;代码第2部分所在
contacting.html;用来显示如'PAGE LOADING.."等临时信息的网页
main.html;真正的主网页
4个图像分别为
x_a.gif; active
x_d.gif; mouseDown
x_o.gif; mouseOver
以上三个文件分别代表关闭窗口图标的不同状态
none.gif; 用来遮盖chromelesstit.html
*/

/*使用方法
如果你想让一个文件,如1.html,中的某一个连接打开一个指像main.html的无边框窗口。
把代码第一部分放到该文件中。
然后将连接

  1<a herf="main.html">   
  2改为   
  3<a herf="#" onclick="doOpen()">   
  4在该文件所在目录内   
  51.建立   
  6chromelesstit.html;   
  7contacting.html;   
  8load.html;   
  9等三个文件,其HTML代码见本文所附。(不要做任何修改)   
 102.建立   
 11一个名为images的目录(注意大小写,与有则不用),将   
 12http//lain.oso.com.cn/x_a.gif;   
 13http//lain.oso.com.cn/x_d.gif;   
 14http//lain.oso.com.cn/x_o.gif;   
 15http//lain.oso.com.cn/none.gif;   
 16这4个文件拷入改目录.   
 17对于初学者,以上则足够了。如果想要更好的效果,自己改代码。   
 18*/   
 19<!--//代码第一部分。   
 20function doOpen(){   
 21theurl="main.html";   
 22wname ="name";   
 23w=750;   
 24h=400;   
 25/* 参数说明:   
 26theurl="main.html"; 打开窗口的网址   
 27wname ="name"; 打开窗口的name属性   
 28w=750; 打开窗口的宽度   
 29h=400; 打开窗口的高度   
 30*/   
 31open(theurl, wname, w, h);   
 32};   
 33function open(theURL, wname, W, H) {   
 34var windowW = W;//确定网页的宽度   
 35var windowH = H;//确定网页的高度   
 36var windowX = Math.ceil( (window.screen.width - windowW) / 2 );   
 37var windowY = Math.ceil( (window.screen.height - windowH) / 2 );//确定网页的坐标   
 38  
 39if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) isie=true; else isie=false;   
 40s = ",width="+W+",height="+H;   
 41if (isie===false){//加入对Nescape系列浏览器的支持   
 42splashWin = window.open( "main.html" , wname, "fullscreen=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s)   
 43splashWin.resizeTo( Math.ceil( W ) , Math.ceil( H ) )   
 44splashWin.moveTo ( Math.ceil( windowX ) , Math.ceil( windowY ) )   
 45}else{   
 46splashWin = window.open( "" , wname, "fullscreen=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s)   
 47splashWin.resizeTo( Math.ceil( W ) , Math.ceil( H ) )   
 48splashWin.moveTo ( Math.ceil( windowX ) , Math.ceil( windowY ) )   
 49splashWin.document.open("text/html", "replace");   
 50splashWin.document.write("<html><style type='text/css'>\n");   
 51splashWin.document.write("body{border: 1px solid #000000; overflow: hidden; margin: 0pt;}");   
 52splashWin.document.write("#stillloadingDiv {position: absolute; left: 0px; top: 0px; width: 100%px; height: 19px; z-index: 1; background-color: #C0C0C0; layer-background-color: #C0C0C0; clip:rect(0,100%,19,0);}");   
 53splashWin.document.write("</style>\n");   
 54splashWin.document.write("<body onload=\"top.document.location.replace('load.html")\" TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 scroll='no'>");   
 55splashWin.document.write("<div id=stillloadingDiv><table width=100% height=22 cellspacing=0 cellpadding=0><tr><td align=left valign=middle width=100%><FONT size=1 face=verdana color=#000000>&nbsp;&nbsp;System energizing ...</font></td></tr></table></div>");   
 56splashWin.document.write("</body></html>");   
 57splashWin.document.close();   
 58}   
 59splashWin.focus();//代码第一部分完   
 60}//-->   
 61  
 62  
 63  
 64chromelesstit.html 文件代码   
 65  
 66<html><head>
 67<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
 68<style type="text/css">   
 69#mywindowTITLE { position: absolute; left: 0px; top: 0px; width: 100%; height: 22px; z-index: 1; background-color: #ffffff; clip:rect(0,100%,22,0); }   
 70#mywindow { position: absolute; left: 0px; top: 0px; width: 100%; height: 22px; z-index: 2; clip:rect(0,100%;22,0); }   
 71#mywindowCLOSE { position: absolute; left: -22px; top: -22px; width: 11px; height: 11px; z-index: 3; clip:rect(0,11,11,0); }   
 72</style>
 73<script language="javascript" type="text/javascript">   
 74// Chromeless window v1.1 (TITLE)   
 75//////////////////////////////////////////////////////////////// Title bar control //////   
 76  
 77var isinit = false;   
 78var mywindowok = true;   
 79  
 80  
 81theURL="main.html"   
 82windowCERRARa = "images/x_a.gif"   
 83windowCERRARd = "images/x_d.gif"   
 84windowCERRARo = "images/x_o.gif"   
 85windowTIT = "<font face=Arial size=1>Title</font>"   
 86windowBORDERCOLOR = "#000000"   
 87windowBORDERCOLORsel = "#FF8A00"   
 88windowTITBGCOLOR = "#d7dcd9"   
 89windowTITBGCOLORsel = "#ffffff"   
 90  
 91var windowCERRARImg_a = new Image(); windowCERRARImg_a.src=windowCERRARa;   
 92var windowCERRARImg_d = new Image(); windowCERRARImg_d.src=windowCERRARd;   
 93var windowCERRARImg_o = new Image(); windowCERRARImg_o.src=windowCERRARo;   
 94  
 95  
 96function whaitborders(){   
 97if ( parent.chromewinb && parent.chromewinl && parent.chromewinr ){   
 98parent.chromewinb.document.bgColor=windowBORDERCOLOR   
 99parent.chromewinl.document.bgColor=windowBORDERCOLOR   
100parent.chromewinr.document.bgColor=windowBORDERCOLOR   
101}else{   
102setTimeout('whaitborders()', 100);   
103}   
104}   
105whaitborders()   
106  
107//////////////////////////////////////////////////////////////// MOUSE MOVE //////   
108  
109function mouseSTATUS(){   
110this.x = null;   
111this.y = null;   
112this.bt = "up";   
113this.oldx = null;   
114this.oldy = null;   
115this.dx = null;   
116this.dy = null;   
117this.screeny = null;   
118this.screenx = null;   
119  
120this.element = null;   
121this.event = null;   
122}   
123  
124var mouse = new mouseSTATUS();   
125  
126function actualizateMouseSTATUS(e){   
127if (!e) var e = event   
128if ( (e.type=="mousedown" || e.type=="mouseup") && e.button!=1) return true   
129  
130var x=e.x+document.body.scrollLeft   
131var y=e.y+document.body.scrollTop   
132  
133mouse.x = x;   
134mouse.y = y;   
135  
136if ( e.type == "mousedown" ) mouse.bt = "down";   
137else if ( e.type == "mouseup" ) mouse.bt = "up";   
138  
139if (window.event){   
140mouse.screenx=window.event.screenX;   
141mouse.screeny=window.event.screenY;   
142}else{   
143mouse.screenx=-1;   
144mouse.screeny=-1;   
145}   
146  
147}   
148  
149  
150function initMouseEvents(){   
151document.onmousedown = actualizateMouseSTATUS   
152document.onmousemove = actualizateMouseSTATUS   
153document.onmouseup = actualizateMouseSTATUS   
154document.onselectstart = selectstart   
155document.ondragstart = new Function("actualizateMouseSTATUS(event); return false;")   
156}   
157  
158function selectstart(){   
159if ( event.srcElement.tagName != "INPUT" && event.srcElement.tagName != "TEXTAREA"){return false;}   
160else{mouse.bt="up"; return true;}   
161}   
162  
163initMouseEvents()   
164  
165//////////////////////////////////////////////////////////////// WINDOW DRAG //////   
166  
167var mywindowbt ="up";   
168var wincloseSTATUS="up";   
169  
170var ofx=0;   
171var ofy=0;   
172var opx=0;   
173var opy=0;   
174var px=0;   
175var py=0;   
176  
177var wcpx1=-1, wcpy1=-1;   
178var wcpx2=-1, wcpy2=-1;   
179  
180var wclosechanged = false;   
181  
182function initToMoveWin(){   
183if (mywindowok){   
184if (wincloseSTATUS=="up" && ( mywindowbt=="up" || mywindowbt=="over") ){   
185if (isinit){   
186wcpx1 = document.all["mywindowCLOSE"].style.pixelLeft=document.body.clientWidth-18   
187wcpy1 = document.all["mywindowCLOSE"].style.pixelTop =4   
188wcpx2 = wcpx1 + 11 - 1   
189wcpy2 = wcpy1 + 11 - 1   
190if ( mouse.x >= wcpx1 && mouse.x <= wcpx2 && mouse.y >= wcpy1 && mouse.y <= wcpy2){   
191if (wclosechanged == false){   
192document.all["mywindowCLOSE"].document.images["closewin"].src=windowCERRARImg_o.src   
193wclosechanged = true   
194}   
195  
196}else if (wclosechanged == true){   
197document.all["mywindowCLOSE"].document.images["closewin"].src=windowCERRARImg_d.src   
198wclosechanged = false   
199}   
200}   
201}   
202  
203if ( mouse.y <= 22 && mouse.y >= 1 && mywindowbt == "up" && mouse.bt =="up" ){mywindowbt = "over"}   
204else if ( ( mouse.y > 22 || mouse.y < 1 ) && mywindowbt == "over" && mouse.bt =="up" ){mywindowbt = "up"}   
205else if ( mouse.y <= 22 && mouse.y >= 1 && mywindowbt == "over" && mouse.bt == "down" ){   
206self.window.focus();   
207  
208if ( mouse.x >= wcpx1 && mouse.x <= wcpx2 && mouse.y >= wcpy1 && mouse.y <= wcpy2 ){   
209wincloseSTATUS="down"   
210document.all["mywindowCLOSE"].document.images["closewin"].src=windowCERRARImg_a.src   
211}else{   
212document.all["mywindowTITLE"].style.backgroundColor = windowTITBGCOLORsel   
213document.body.style.borderColor = windowBORDERCOLORsel   
214parent.chromewinb.document.bgColor=windowBORDERCOLORsel   
215parent.chromewinl.document.bgColor=windowBORDERCOLORsel   
216parent.chromewinr.document.bgColor=windowBORDERCOLORsel   
217ofx = mouse.x;   
218ofy = mouse.y;   
219opx = mouse.x;   
220opy = mouse.y;   
221}   
222mywindowbt="down";   
223}   
224else if ( mouse.bt =="up" && mywindowbt == "down" ){   
225mywindowbt="up";   
226ofx=0;   
227ofy=0;   
228opx=0;   
229opy=0;   
230  
231if ( mouse.x >= wcpx1 && mouse.x <= wcpx2 && mouse.y >= wcpy1 && mouse.y <= wcpy2 && wincloseSTATUS=="down" ){top.window.close()}   
232  
233wincloseSTATUS="up"   
234  
235if ( document.all["mywindowTITLE"] ){   
236document.all["mywindowTITLE"].style.backgroundColor = windowTITBGCOLOR   
237document.body.style.borderColor = windowBORDERCOLOR   
238parent.chromewinb.document.bgColor=windowBORDERCOLOR   
239parent.chromewinl.document.bgColor=windowBORDERCOLOR   
240parent.chromewinr.document.bgColor=windowBORDERCOLOR   
241}   
242  
243}   
244else if ( mywindowbt == "down" && wincloseSTATUS == "up"){   
245var m_scrx = mouse.screenx;   
246var m_scry = mouse.screeny;   
247opx = px + ofx - m_scrx;   
248opy = py + ofy - m_scry;   
249px = m_scrx - ofx;   
250py = m_scry - ofy;   
251top.window.moveTo(px , py);   
252}   
253}   
254setTimeout('initToMoveWin()',20);   
255}   
256initToMoveWin()   
257  
258//////////////////////////////////////////////////////////////// WRITE TITLE //////   
259  
260function init(){   
261document.all["mywindowTITLE"].innerHTML='<table width=100% height=20 border=0 cellpadding=0 cellspacing=0><tr><td valign=middle align=left>'+windowTIT+'</td></tr></table>'   
262document.all["mywindowTITLE"].style.backgroundColor = windowTITBGCOLOR   
263document.all["mywindowCLOSE"].document.images["closewin"].src=windowCERRARImg_d.src   
264  
265setTimeout('parent.main.location.replace("'+theURL+'")',200)   
266  
267isinit=true   
268}   
269  
270</script></head>
271<body bgcolor="#ffffff" leftmargin="0" marginheight="0" marginwidth="0" onload="init()" scroll="no" style="border:1px solid #000000;overflow:hidden;margin:0pt;" topmargin="0">
272<div id="mywindow">
273<img height="20" src="images/none.gif" width="100%"/>
274</div>
275<div id="mywindowTITLE">
276<img height="1" width="1"/>
277</div>
278<div id="mywindowCLOSE">
279<img border="0" height="11" name="closewin" src="images/none.gif" width="11"/>
280</div>
281</body>
282</html>   
283  
284  
285contacting.html 文件代码   
286  
287<html>
288<head>
289<style type="text/css">   
290body { border: 0px; overflow: hidden; margin: 0pt;}   
291#stillloadingDiv { position: absolute; left: 0px; top: 0px; width: 100%; height: 19px; z-index: 1; background-color: #C0C0C0; layer-background-color: #C0C0C0; clip:rect(0,100%,19,0);}   
292</style>
293</head>
294<body leftmargin="0" marginheight="0" marginwidth="0" scroll="no" topmargin="0">
295<div id="stillloadingDiv"><table cellpadding="0" cellspacing="0" height="22" width="100%"><tr><td align="left" valign="middle" width="100%"><font color="#000000" face="verdana" size="1">  loading, please wait. . .</font></td></tr></table></div>
296</body>
297</html>   
298  
299laod.html 文件代码   
300  
301<html>
302<head>
303<title>OF KAI</title>
304</head>
305<frameset border="0" frameborder="0" framespacing="0" rows="22,100%,1">
306<frame name="chromewint" noresize="" scrolling="no" src="chromelesstit.html"/>
307<frameset border="0" cols="1,100%,1" frameborder="0" framespacing="0">
308<frame name="chromewinl" noresize="" scrolling="no" src="about:blank"/>
309<frame name="main" noresize="" scrolling="no" src="contacting.html"/>
310<frame name="chromewinr" noresize="" scrolling="no" src="about:blank"/>
311</frameset>
312<frame name="chromewinb" noresize="" scrolling="no" src="about:blank"/>
313<noframes>
314</noframes>
315</frameset>
316<frameset>
317</frameset>
318</html>   
319  
320  
321【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】</a></a>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus