用层(DIV)来实现弹出窗口

现在网上有很的软件用来阻止网页中的弹出窗口,本来倒是好事,用户可以根据需要来阻止那些广告什么的。但有很多这种小软件是流氓软件,不知不觉中这装上去了,很多人还装了很多,但又不会设置。这就要我们程序员,来很办法避开这些软件,让用户看到我们所要展示的内容。用户层来模拟弹出窗口,是个不错的选择。
如下图所示:

上面的客户信息窗体就是通过层模拟出来的。
下面是源代码:
windemo.html

ContractedBlock.gif ExpandedBlockStart.gif
None.gif<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif    
<HEAD>
None.gif        
<title>windemo1</title>
None.gif        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
None.gif        
<meta name="CODE_LANGUAGE" Content="C#">
None.gif        
<meta name="vs_defaultClientScript" content="JavaScript">
None.gif        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
None.gif        
<link type="text/css" href="win/win.css" rel="stylesheet">
ExpandedBlockStart.gifContractedBlock.gif        
<script src="win/win.js" language="javascript">dot.gif
ExpandedBlockEnd.gif        
</script>
None.gif    
</HEAD>
None.gif    
<body>
None.gif        
<form id="Form1" method="post" runat="server">
None.gif            
<onclick="if (winList['sample2']) winList['sample2'].open('table.aspx'); return false;"
None.gif                href
="#">客户信息列表</A>
None.gif            
<DIV class="window" id="sample2" style="WIDTH: 870px">
None.gif                
<DIV class="titleBar">
None.gif                    
<SPAN class="titleBarText"><img src="win/MSN.ICO" height="14"> 客户信息</SPAN> <IMG class="titleBarButtons" alt="" useMap="#sampleMap2" src="win/buttons.gif">
None.gif                    
<MAP id="sampleMap2" name="sampleMap2">
None.gif                        
<AREA title="Minimize" onclick="this.parentWindow.minimize();return false;" shape="RECT"
None.gif                            alt
="最小化" coords="0,0,15,13">
None.gif                        
<AREA title="Restore" onclick="this.parentWindow.restore();return false;" shape="RECT"
None.gif                            alt
="还原" coords="16,0,31,13">
None.gif                        
<AREA title="Close" onclick="this.parentWindow.close();return false;" shape="RECT" alt="关闭"
None.gif                            coords
="34,0,49,13">
None.gif                    
</MAP>
None.gif                
</DIV>
None.gif                
<DIV class="clientArea" style="HEIGHT: 530px">
None.gif                    
<iframe id="iurl" frameborder="0" style="MARGIN: 0px" src="" width="100%" height="100%">
None.gif                    
</iframe>
None.gif                
</DIV>
None.gif            
</DIV>
None.gif        
</form>
None.gif    
</body>
None.gif
</HTML>
可以修改<div class="clientArea"></div>中的内容,去掉<iframe>标记,直接添加显示内容,在调用onclick,打开窗体时,用open(),不带参数。
win.css
ContractedBlock.gif ExpandedBlockStart.gif
ExpandedBlockStart.gifContractedBlock.gif.lastLine {dot.gif}{ PADDING-LEFT: 6em }
None.gif.window 
ExpandedBlockStart.gifContractedBlock.gif
{dot.gif}{
InBlock.gif    BORDER-RIGHT
: #606060 2px solid; 
InBlock.gif    PADDING-RIGHT
: 2px; 
InBlock.gif    BORDER-TOP
: #f0f0f0 2px solid; 
InBlock.gif    PADDING-LEFT
: 2px; 
InBlock.gif    VISIBILITY
: hidden; 
InBlock.gif    PADDING-BOTTOM
: 2px; 
InBlock.gif    MARGIN
: 0px; 
InBlock.gif    BORDER-LEFT
: #d0d0d0 2px solid; 
InBlock.gif    PADDING-TOP
: 2px; 
InBlock.gif    BORDER-BOTTOM
: #404040 2px solid; 
InBlock.gif    POSITION
: absolute; 
InBlock.gif    BACKGROUND-COLOR
: #c0c0c0; 
InBlock.gif    TEXT-ALIGN
: left 
ExpandedBlockEnd.gif    
}

None.gif.titleBar 
ExpandedBlockStart.gifContractedBlock.gif
{dot.gif}{
InBlock.gif    PADDING-RIGHT
: 2px; 
InBlock.gif    PADDING-LEFT
: 0.5em; 
InBlock.gif    FONT-WEIGHT
: bold; 
InBlock.gif    FONT-SIZE
: 8pt; 
InBlock.gif    PADDING-BOTTOM
: 2px; 
InBlock.gif    MARGIN
: 0px; 
InBlock.gif    CURSOR
: default; 
InBlock.gif    COLOR
: #ffffff; 
InBlock.gif    PADDING-TOP
: 2px; 
InBlock.gif    FONT-FAMILY
: "MS Sans Serif", "Arial", "Helvetica", sans-serif; 
InBlock.gif    WHITE-SPACE
: nowrap; 
InBlock.gif    BACKGROUND-COLOR
:#0054e3;
InBlock.gif    TEXT-ALIGN
: right 
InBlock.gif    
ExpandedBlockEnd.gif    
}

ExpandedBlockStart.gifContractedBlock.gif.titleBarText 
{dot.gif}{ FLOAT: left; OVERFLOW: hidden; TEXT-ALIGN: left; }
None.gif.titleBarButtons 
ExpandedBlockStart.gifContractedBlock.gif
{dot.gif}{
InBlock.gif    BORDER-RIGHT
: 0px; 
InBlock.gif    BORDER-TOP
: 0px; 
InBlock.gif    VERTICAL-ALIGN
: middle; 
InBlock.gif    BORDER-LEFT
: 0px; 
InBlock.gif    WIDTH
: 50px; 
InBlock.gif    BORDER-BOTTOM
: 0px; 
InBlock.gif    HEIGHT
: 14px; 
ExpandedBlockEnd.gif    
}

None.gif.clientArea 
ExpandedBlockStart.gifContractedBlock.gif
{dot.gif}{
InBlock.gif    BORDER-RIGHT
: #e0e0e0 2px solid; 
InBlock.gif    PADDING-RIGHT
: 0.0em; 
InBlock.gif    BORDER-TOP
: #404040 2px solid; 
InBlock.gif    PADDING-LEFT
: 0.0em; FONT-SIZE: 10pt; 
InBlock.gif    PADDING-BOTTOM
: 0.0em; 
InBlock.gif    MARGIN
: 2px 0px 0px; 
InBlock.gif    OVERFLOW
: auto; 
InBlock.gif    BORDER-LEFT
: #505050 2px solid; 
InBlock.gif    COLOR
: #000000; 
InBlock.gif    PADDING-TOP
: 0.0em; 
InBlock.gif    BORDER-BOTTOM
: #f0f0f0 2px solid; 
InBlock.gif    FONT-FAMILY
: "Arial", "Helvetica", sans-serif; 
InBlock.gif    BACKGROUND-COLOR
: #ffffff; 
InBlock.gif    height
:100%;
InBlock.gif     width
:100% 
ExpandedBlockEnd.gif     
}

None.gif

win.js
ContractedBlock.gif ExpandedBlockStart.gif
None.gif
None.gif
//<![CDATA[
None.gif//
*****************************************************************************
None.gif//
 Do not remove this notice.
None.gif//
None.gif//
 Copyright 2001 by Mike Hall.
None.gif//
 See http://www.brainjar.com for terms of use.
None.gif//
*****************************************************************************
None.gif

None.gif
// Determine browser and version.
None.gif

ExpandedBlockStart.gifContractedBlock.gif
function Browser() dot.gif{
InBlock.gif
InBlock.gif  
var ua, s, i;
InBlock.gif
InBlock.gif  
this.isIE    = false;  // Internet Explorer
InBlock.gif
  this.isNS    = false;  // Netscape
InBlock.gif
  this.version = null;
InBlock.gif
InBlock.gif  ua 
= navigator.userAgent;
InBlock.gif
InBlock.gif  s 
= "MSIE";
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if ((i = ua.indexOf(s)) >= 0dot.gif{
InBlock.gif    
this.isIE = true;
InBlock.gif    
this.version = parseFloat(ua.substr(i + s.length));
InBlock.gif    
return;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  s 
= "Netscape6/";
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if ((i = ua.indexOf(s)) >= 0dot.gif{
InBlock.gif    
this.isNS = true;
InBlock.gif    
this.version = parseFloat(ua.substr(i + s.length));
InBlock.gif    
return;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// Treat any other "Gecko" browser as NS 6.1.
InBlock.gif

InBlock.gif  s 
= "Gecko";
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if ((i = ua.indexOf(s)) >= 0dot.gif{
InBlock.gif    
this.isNS = true;
InBlock.gif    
this.version = 6.1;
InBlock.gif    
return;
ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif}

None.gif
None.gif
var browser = new Browser();
None.gif
None.gif
//=============================================================================
None.gif//
 Window Object
None.gif//
=============================================================================
None.gif

ExpandedBlockStart.gifContractedBlock.gif
function Window(el) dot.gif{
InBlock.gif
InBlock.gif  
var i, mapList, mapName;
InBlock.gif
InBlock.gif  
// Get window components.
InBlock.gif

InBlock.gif  
this.frame           = el;
InBlock.gif  
this.titleBar        = winFindByClassName(el, "titleBar");
InBlock.gif  
this.titleBarText    = winFindByClassName(el, "titleBarText");
InBlock.gif  
this.titleBarButtons = winFindByClassName(el, "titleBarButtons");
InBlock.gif  
this.clientArea      = winFindByClassName(el, "clientArea");
InBlock.gif
InBlock.gif  
// Find matching button image map.
InBlock.gif

InBlock.gif  mapName 
= this.titleBarButtons.useMap.substr(1);
InBlock.gif  mapList 
= document.getElementsByTagName("MAP");
InBlock.gif  
for (i = 0; i < mapList.length; i++)
InBlock.gif    
if (mapList[i].name == mapName)
InBlock.gif      
this.titleBarMap = mapList[i];
InBlock.gif
InBlock.gif  
// Save colors.
InBlock.gif

InBlock.gif  
this.activeFrameBackgroundColor  = this.frame.style.backgroundColor;
InBlock.gif  
this.activeFrameBorderColor      = this.frame.style.borderColor;
InBlock.gif  
this.activeTitleBarColor         = this.titleBar.style.backgroundColor;
InBlock.gif  
this.activeTitleTextColor        = this.titleBar.style.color;
InBlock.gif  
this.activeClientAreaBorderColor = this.clientArea.style.borderColor;
InBlock.gif  
if (browser.isIE)
InBlock.gif    
this.activeClientAreaScrollbarColor = this.clientArea.style.scrollbarBaseColor;
InBlock.gif
InBlock.gif  
// Save images.
InBlock.gif

InBlock.gif  
this.activeButtonsImage   = this.titleBarButtons.src;
InBlock.gif  
this.inactiveButtonsImage = this.titleBarButtons.longDesc;
InBlock.gif
InBlock.gif  
// Set flags.
InBlock.gif

InBlock.gif  
this.isOpen      = false;
InBlock.gif  
this.isMinimized = false;
InBlock.gif
InBlock.gif  
// Set methods.
InBlock.gif

InBlock.gif  
this.open       = winOpen;
InBlock.gif  
this.close      = winClose;
InBlock.gif  
this.minimize   = winMinimize;
InBlock.gif  
this.restore    = winRestore;
InBlock.gif  
this.makeActive = winMakeActive;
InBlock.gif
InBlock.gif  
// Set up event handling.
InBlock.gif

InBlock.gif  
this.frame.parentWindow = this;
InBlock.gif  
this.frame.onmousemove  = winResizeCursorSet;
InBlock.gif  
this.frame.onmouseout   = winResizeCursorRestore;
InBlock.gif  
this.frame.onmousedown  = winResizeDragStart;
InBlock.gif
InBlock.gif  
this.titleBar.parentWindow = this;
InBlock.gif  
this.titleBar.onmousedown  = winMoveDragStart;
InBlock.gif
InBlock.gif  
this.clientArea.parentWindow = this;
InBlock.gif  
this.clientArea.onclick      = winClientAreaClick;
InBlock.gif
InBlock.gif  
for (i = 0; i < this.titleBarMap.childNodes.length; i++)
InBlock.gif    
if (this.titleBarMap.childNodes[i].tagName == "AREA")
InBlock.gif      
this.titleBarMap.childNodes[i].parentWindow = this;
InBlock.gif
InBlock.gif  
// Calculate the minimum width and height values for resizing
InBlock.gif
  // and fix any initial display problems.
InBlock.gif

InBlock.gif  
var initLt, initWd, w, dw;
InBlock.gif
InBlock.gif  
// Save the inital frame width and position, then reposition
InBlock.gif
  // the window.
InBlock.gif

InBlock.gif  initLt 
= this.frame.style.left;
InBlock.gif  initWd 
= parseInt(this.frame.style.width);
InBlock.gif  
this.frame.style.left = -this.titleBarText.offsetWidth + "px";
InBlock.gif
InBlock.gif  
// For IE, start calculating the value to use when setting
InBlock.gif
  // the client area width based on the frame width.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    
this.titleBarText.style.display = "none";
InBlock.gif    w 
= this.clientArea.offsetWidth;
InBlock.gif    
this.widthDiff = this.frame.offsetWidth - w;
InBlock.gif    
this.clientArea.style.width = w + "px";
InBlock.gif    dw 
= this.clientArea.offsetWidth - w;
InBlock.gif    w 
-= dw;     
InBlock.gif    
this.widthDiff += dw;
InBlock.gif    
this.titleBarText.style.display = "";
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// Find the difference between the frame's style and offset
InBlock.gif
  // widths. For IE, adjust the client area/frame width
InBlock.gif
  // difference accordingly.
InBlock.gif

InBlock.gif  w 
= this.frame.offsetWidth;
InBlock.gif  
this.frame.style.width = w + "px";
InBlock.gif  dw 
= this.frame.offsetWidth - w;
InBlock.gif  w 
-= dw;     
InBlock.gif  
this.frame.style.width = w + "px";
InBlock.gif  
if (browser.isIE)
InBlock.gif    
this.widthDiff -= dw;
InBlock.gif
InBlock.gif  
// Find the minimum width for resize.
InBlock.gif

InBlock.gif  
this.isOpen = true;  // Flag as open so minimize call will work.
InBlock.gif
  this.minimize();
InBlock.gif  
// Get the minimum width.
InBlock.gif
  if (browser.isNS && browser.version >= 1.2)
InBlock.gif    
// For later versions of Gecko.
InBlock.gif
    this.minimumWidth = this.frame.offsetWidth;
InBlock.gif  
else
InBlock.gif    
// For all others.
InBlock.gif
    this.minimumWidth = this.frame.offsetWidth - dw;
InBlock.gif
InBlock.gif  
// Find the frame width at which or below the title bar text will
InBlock.gif
  // need to be clipped.
InBlock.gif

InBlock.gif  
this.titleBarText.style.width = "";
InBlock.gif  
this.clipTextMinimumWidth = this.frame.offsetWidth - dw;
InBlock.gif
InBlock.gif  
// Set the minimum height.
InBlock.gif

InBlock.gif  
this.minimumHeight = 1;
InBlock.gif
InBlock.gif  
// Restore window. For IE, set client area width.
InBlock.gif

InBlock.gif  
this.restore();
InBlock.gif  
this.isOpen = false;  // Reset flag.
InBlock.gif
  initWd = Math.max(initWd, this.minimumWidth);
InBlock.gif  
this.frame.style.width = initWd + "px";
InBlock.gif  
if (browser.isIE)
InBlock.gif    
this.clientArea.style.width = (initWd - this.widthDiff) + "px";
InBlock.gif
InBlock.gif  
// Clip the title bar text if needed.
InBlock.gif

InBlock.gif  
if (this.clipTextMinimumWidth >= this.minimumWidth)
InBlock.gif    
this.titleBarText.style.width = (winCtrl.minimizedTextWidth + initWd - this.minimumWidth) + "px";
InBlock.gif
InBlock.gif  
// Restore the window to its original position.
InBlock.gif

InBlock.gif  
this.frame.style.left = initLt;
ExpandedBlockEnd.gif}

None.gif
None.gif
//=============================================================================
None.gif//
 Window Methods
None.gif//
=============================================================================
None.gif

ExpandedBlockStart.gifContractedBlock.gif
function winOpen() dot.gif{
InBlock.gif
InBlock.gif  
if (this.isOpen)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// Restore the window and make it visible.
InBlock.gif

InBlock.gif  
this.makeActive();
InBlock.gif  
this.isOpen = true;
InBlock.gif  
if (this.isMinimized)
InBlock.gif    
this.restore();
InBlock.gif  
this.frame.style.visibility = "visible";
InBlock.gif  
if(arguments[0]!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif     
var iurl = document.getElementById("iurl");
InBlock.gif      iurl.setAttribute(
"src",arguments[0]);
ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winClose() dot.gif{
InBlock.gif
InBlock.gif  
// Hide the window.
InBlock.gif

InBlock.gif  
this.frame.style.visibility = "hidden";
InBlock.gif  
this.isOpen = false;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winMinimize() dot.gif{
InBlock.gif
InBlock.gif  
if (!this.isOpen || this.isMinimized)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
this.makeActive();
InBlock.gif
InBlock.gif  
// Save current frame and title bar text widths.
InBlock.gif

InBlock.gif  
this.restoreFrameWidth = this.frame.style.width;
InBlock.gif  
this.restoreTextWidth = this.titleBarText.style.width;
InBlock.gif
InBlock.gif  
// Disable client area display.
InBlock.gif

InBlock.gif  
this.clientArea.style.display = "none";
InBlock.gif
InBlock.gif  
// Minimize frame and title bar text widths.
InBlock.gif

InBlock.gif  
if (this.minimumWidth)
InBlock.gif    
this.frame.style.width = this.minimumWidth + "px";
InBlock.gif  
else
InBlock.gif    
this.frame.style.width = "";
InBlock.gif  
this.titleBarText.style.width = winCtrl.minimizedTextWidth + "px";
InBlock.gif
InBlock.gif  
this.isMinimized = true;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winRestore() dot.gif{
InBlock.gif
InBlock.gif  
if (!this.isOpen || !this.isMinimized)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
this.makeActive();
InBlock.gif
InBlock.gif  
// Enable client area display.
InBlock.gif

InBlock.gif  
this.clientArea.style.display = "";
InBlock.gif
InBlock.gif  
// Restore frame and title bar text widths.
InBlock.gif

InBlock.gif  
this.frame.style.width = this.restoreFrameWidth;
InBlock.gif  
this.titleBarText.style.width = this.restoreTextWidth;
InBlock.gif
InBlock.gif  
this.isMinimized = false;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winMakeActive() dot.gif{
InBlock.gif
InBlock.gif  
if (winCtrl.active == this)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// Inactivate the currently active window.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (winCtrl.active) dot.gif{
InBlock.gif    winCtrl.active.frame.style.backgroundColor    
= winCtrl.inactiveFrameBackgroundColor;
InBlock.gif    winCtrl.active.frame.style.borderColor        
= winCtrl.inactiveFrameBorderColor;
InBlock.gif    winCtrl.active.titleBar.style.backgroundColor 
= winCtrl.inactiveTitleBarColor;
InBlock.gif    winCtrl.active.titleBar.style.color           
= winCtrl.inactiveTitleTextColor;
InBlock.gif    winCtrl.active.clientArea.style.borderColor   
= winCtrl.inactiveClientAreaBorderColor;
InBlock.gif    
if (browser.isIE)
InBlock.gif      winCtrl.active.clientArea.style.scrollbarBaseColor 
= winCtrl.inactiveClientAreaScrollbarColor;
InBlock.gif    
if (browser.isNS && browser.version < 6.1)
InBlock.gif      winCtrl.active.clientArea.style.overflow 
= "hidden";
InBlock.gif    
if (winCtrl.active.inactiveButtonsImage)
InBlock.gif      winCtrl.active.titleBarButtons.src 
= winCtrl.active.inactiveButtonsImage;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// Activate this window.
InBlock.gif

InBlock.gif  
this.frame.style.backgroundColor    = this.activeFrameBackgroundColor;
InBlock.gif  
this.frame.style.borderColor        = this.activeFrameBorderColor;
InBlock.gif  
this.titleBar.style.backgroundColor = this.activeTitleBarColor;
InBlock.gif  
this.titleBar.style.color           = this.activeTitleTextColor;
InBlock.gif  
this.clientArea.style.borderColor   = this.activeClientAreaBorderColor;
InBlock.gif  
if (browser.isIE)
InBlock.gif    
this.clientArea.style.scrollbarBaseColor = this.activeClientAreaScrollbarColor;
InBlock.gif  
if (browser.isNS && browser.version < 6.1)
InBlock.gif    
this.clientArea.style.overflow = "auto";
InBlock.gif  
if (this.inactiveButtonsImage)
InBlock.gif    
this.titleBarButtons.src = this.activeButtonsImage;
InBlock.gif  
this.frame.style.zIndex = ++winCtrl.maxzIndex;
InBlock.gif  winCtrl.active 
= this;
ExpandedBlockEnd.gif}

None.gif
None.gif
//=============================================================================
None.gif//
 Event handlers.
None.gif//
=============================================================================
None.gif

ExpandedBlockStart.gifContractedBlock.gif
function winClientAreaClick(event) dot.gif{
InBlock.gif
InBlock.gif  
// Make this window the active one.
InBlock.gif

InBlock.gif  
this.parentWindow.makeActive();
ExpandedBlockEnd.gif}

None.gif
None.gif
//-----------------------------------------------------------------------------
None.gif//
 Window dragging.
None.gif//
-----------------------------------------------------------------------------
None.gif

ExpandedBlockStart.gifContractedBlock.gif
function winMoveDragStart(event) dot.gif{
InBlock.gif
InBlock.gif  
var target;
InBlock.gif  
var x, y;
InBlock.gif
InBlock.gif  
if (browser.isIE)
InBlock.gif    target 
= window.event.srcElement.tagName;
InBlock.gif  
if (browser.isNS)
InBlock.gif    target 
= event.target.tagName;
InBlock.gif
InBlock.gif  
if (target == "AREA")
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
this.parentWindow.makeActive();
InBlock.gif
InBlock.gif  
// Get cursor offset from window frame.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    x 
= window.event.x;
InBlock.gif    y 
= window.event.y;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    x 
= event.pageX;
InBlock.gif    y 
= event.pageY;
ExpandedSubBlockEnd.gif  }

InBlock.gif  winCtrl.xOffset 
= winCtrl.active.frame.offsetLeft - x;
InBlock.gif  winCtrl.yOffset 
= winCtrl.active.frame.offsetTop  - y;
InBlock.gif
InBlock.gif  
// Set document to capture mousemove and mouseup events.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    document.onmousemove 
= winMoveDragGo;
InBlock.gif    document.onmouseup   
= winMoveDragStop;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    document.addEventListener(
"mousemove", winMoveDragGo,   true);
InBlock.gif    document.addEventListener(
"mouseup",   winMoveDragStop, true);
InBlock.gif    event.preventDefault();
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  winCtrl.inMoveDrag 
= true;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winMoveDragGo(event) dot.gif{
InBlock.gif
InBlock.gif  
var x, y;
InBlock.gif
InBlock.gif  
if (!winCtrl.inMoveDrag)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// Get cursor position.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    x 
= window.event.x;
InBlock.gif    y 
= window.event.y;
InBlock.gif    window.event.cancelBubble 
= true;
InBlock.gif    window.event.returnValue 
= false;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    x 
= event.pageX;
InBlock.gif    y 
= event.pageY;
InBlock.gif    event.preventDefault();
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// Move window frame based on offset from cursor.
InBlock.gif

InBlock.gif  winCtrl.active.frame.style.left 
= (x + winCtrl.xOffset) + "px";
InBlock.gif  winCtrl.active.frame.style.top  
= (y + winCtrl.yOffset) + "px";
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winMoveDragStop(event) dot.gif{
InBlock.gif
InBlock.gif  winCtrl.inMoveDrag 
= false;
InBlock.gif
InBlock.gif  
// Remove mousemove and mouseup event captures on document.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    document.onmousemove 
= null;
InBlock.gif    document.onmouseup   
= null;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    document.removeEventListener(
"mousemove", winMoveDragGo,   true);
InBlock.gif    document.removeEventListener(
"mouseup",   winMoveDragStop, true);
ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif}

None.gif
None.gif
//-----------------------------------------------------------------------------
None.gif//
 Window resizing.
None.gif//
-----------------------------------------------------------------------------
None.gif

ExpandedBlockStart.gifContractedBlock.gif
function winResizeCursorSet(event) dot.gif{
InBlock.gif
InBlock.gif  
var target;
InBlock.gif  
var xOff, yOff;
InBlock.gif
InBlock.gif  
if (this.parentWindow.isMinimized || winCtrl.inResizeDrag)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// If not on window frame, restore cursor and exit.
InBlock.gif

InBlock.gif  
if (browser.isIE)
InBlock.gif    target 
= window.event.srcElement;
InBlock.gif  
if (browser.isNS)
InBlock.gif    target 
= event.target;
InBlock.gif  
if (target != this.parentWindow.frame)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// Find resize direction.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    xOff 
= window.event.offsetX;
InBlock.gif    yOff 
= window.event.offsetY;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    xOff 
= event.layerX;
InBlock.gif    yOff 
= event.layerY;
ExpandedSubBlockEnd.gif  }

InBlock.gif  winCtrl.resizeDirection 
= ""
InBlock.gif  
if (yOff <= winCtrl.resizeCornerSize)
InBlock.gif    winCtrl.resizeDirection 
+= "n";
InBlock.gif  
else if (yOff >= this.parentWindow.frame.offsetHeight - winCtrl.resizeCornerSize)
InBlock.gif    winCtrl.resizeDirection 
+= "s";
InBlock.gif  
if (xOff <= winCtrl.resizeCornerSize)
InBlock.gif    winCtrl.resizeDirection 
+= "w";
InBlock.gif  
else if (xOff >= this.parentWindow.frame.offsetWidth - winCtrl.resizeCornerSize)
InBlock.gif    winCtrl.resizeDirection 
+= "e";
InBlock.gif
InBlock.gif  
// If not on window edge, restore cursor and exit.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (winCtrl.resizeDirection == ""dot.gif{
InBlock.gif    
this.onmouseout(event);
InBlock.gif    
return;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// Change cursor.
InBlock.gif

InBlock.gif  
if (browser.isIE)
InBlock.gif    document.body.style.cursor 
= winCtrl.resizeDirection + "-resize";
InBlock.gif  
if (browser.isNS)
InBlock.gif    
this.parentWindow.frame.style.cursor = winCtrl.resizeDirection + "-resize";
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winResizeCursorRestore(event) dot.gif{
InBlock.gif
InBlock.gif  
if (winCtrl.inResizeDrag)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// Restore cursor.
InBlock.gif

InBlock.gif  
if (browser.isIE)
InBlock.gif    document.body.style.cursor 
= "";
InBlock.gif  
if (browser.isNS)
InBlock.gif    
this.parentWindow.frame.style.cursor = "";
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winResizeDragStart(event) dot.gif{
InBlock.gif
InBlock.gif  
var target;
InBlock.gif
InBlock.gif  
// Make sure the event is on the window frame.
InBlock.gif

InBlock.gif  
if (browser.isIE)
InBlock.gif    target 
= window.event.srcElement;
InBlock.gif  
if (browser.isNS)
InBlock.gif    target 
= event.target;
InBlock.gif  
if (target != this.parentWindow.frame)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
this.parentWindow.makeActive();
InBlock.gif
InBlock.gif  
if (this.parentWindow.isMinimized)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// Save cursor position.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    winCtrl.xPosition 
= window.event.x;
InBlock.gif    winCtrl.yPosition 
= window.event.y;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    winCtrl.xPosition 
= event.pageX;
InBlock.gif    winCtrl.yPosition 
= event.pageY;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// Save window frame position and current window size.
InBlock.gif

InBlock.gif  winCtrl.oldLeft   
= parseInt(this.parentWindow.frame.style.left,  10);
InBlock.gif  winCtrl.oldTop    
= parseInt(this.parentWindow.frame.style.top,   10);
InBlock.gif  winCtrl.oldWidth  
= parseInt(this.parentWindow.frame.style.width, 10);
InBlock.gif  winCtrl.oldHeight 
= parseInt(this.parentWindow.clientArea.style.height, 10);
InBlock.gif
InBlock.gif  
// Set document to capture mousemove and mouseup events.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    document.onmousemove 
= winResizeDragGo;
InBlock.gif    document.onmouseup   
= winResizeDragStop;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    document.addEventListener(
"mousemove", winResizeDragGo,   true);
InBlock.gif    document.addEventListener(
"mouseup"  , winResizeDragStop, true);
InBlock.gif    event.preventDefault();
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  winCtrl.inResizeDrag 
= true;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winResizeDragGo(event) dot.gif{
InBlock.gif
InBlock.gif 
var north, south, east, west;
InBlock.gif 
var dx, dy;
InBlock.gif 
var w, h;
InBlock.gif
InBlock.gif  
if (!winCtrl.inResizeDrag)
InBlock.gif    
return;
InBlock.gif
InBlock.gif  
// Set direction flags based on original resize direction.
InBlock.gif

InBlock.gif  north 
= false;
InBlock.gif  south 
= false;
InBlock.gif  east  
= false;
InBlock.gif  west  
= false;
InBlock.gif  
if (winCtrl.resizeDirection.charAt(0== "n")
InBlock.gif    north 
= true;
InBlock.gif  
if (winCtrl.resizeDirection.charAt(0== "s")
InBlock.gif    south 
= true;
InBlock.gif  
if (winCtrl.resizeDirection.charAt(0== "e" || winCtrl.resizeDirection.charAt(1== "e")
InBlock.gif    east 
= true;
InBlock.gif  
if (winCtrl.resizeDirection.charAt(0== "w" || winCtrl.resizeDirection.charAt(1== "w")
InBlock.gif    west 
= true;
InBlock.gif
InBlock.gif  
// Find change in cursor position.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    dx 
= window.event.x - winCtrl.xPosition;
InBlock.gif    dy 
= window.event.y - winCtrl.yPosition;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    dx 
= event.pageX - winCtrl.xPosition;
InBlock.gif    dy 
= event.pageY - winCtrl.yPosition;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// If resizing north or west, reverse corresponding amount.
InBlock.gif

InBlock.gif  
if (west)
InBlock.gif    dx 
= -dx;
InBlock.gif  
if (north)
InBlock.gif    dy 
= -dy;
InBlock.gif
InBlock.gif  
// Check new size.
InBlock.gif

InBlock.gif  w 
= winCtrl.oldWidth  + dx;
InBlock.gif  h 
= winCtrl.oldHeight + dy;
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (w <= winCtrl.active.minimumWidth) dot.gif{
InBlock.gif    w 
= winCtrl.active.minimumWidth;
InBlock.gif    dx 
= w - winCtrl.oldWidth;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (h <= winCtrl.active.minimumHeight) dot.gif{
InBlock.gif    h 
= winCtrl.active.minimumHeight;
InBlock.gif    dy 
= h - winCtrl.oldHeight;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// Resize the window. For IE, keep client area and frame widths in synch.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (east || west) dot.gif{
InBlock.gif    winCtrl.active.frame.style.width 
= w + "px";
InBlock.gif    
if (browser.isIE)
InBlock.gif      winCtrl.active.clientArea.style.width 
= (w - winCtrl.active.widthDiff) + "px";
ExpandedSubBlockEnd.gif  }

InBlock.gif  
if (north || south)
InBlock.gif    winCtrl.active.clientArea.style.height 
= h + "px";
InBlock.gif
InBlock.gif  
// Clip the title bar text, if necessary.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (east || west) dot.gif{
InBlock.gif    
if (w < winCtrl.active.clipTextMinimumWidth)
InBlock.gif      winCtrl.active.titleBarText.style.width 
= (winCtrl.minimizedTextWidth + w - winCtrl.active.minimumWidth) + "px";
InBlock.gif    
else
InBlock.gif      winCtrl.active.titleBarText.style.width 
= "";
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
// For a north or west resize, move the window.
InBlock.gif

InBlock.gif  
if (west)
InBlock.gif    winCtrl.active.frame.style.left 
= (winCtrl.oldLeft - dx) + "px";
InBlock.gif  
if (north)
InBlock.gif    winCtrl.active.frame.style.top  
= (winCtrl.oldTop  - dy) + "px";
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    window.event.cancelBubble 
= true;
InBlock.gif    window.event.returnValue 
= false;
ExpandedSubBlockEnd.gif  }

InBlock.gif  
if (browser.isNS)
InBlock.gif    event.preventDefault();
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winResizeDragStop(event) dot.gif{
InBlock.gif
InBlock.gif  winCtrl.inResizeDrag 
= false;
InBlock.gif
InBlock.gif  
// Remove mousemove and mouseup event captures on document.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isIE) dot.gif{
InBlock.gif    document.onmousemove 
= null;
InBlock.gif    document.onmouseup   
= null;
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (browser.isNS) dot.gif{
InBlock.gif    document.removeEventListener(
"mousemove", winResizeDragGo,   true);
InBlock.gif    document.removeEventListener(
"mouseup"  , winResizeDragStop, true);
ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif}

None.gif
None.gif
//=============================================================================
None.gif//
 Utility functions.
None.gif//
=============================================================================
None.gif

ExpandedBlockStart.gifContractedBlock.gif
function winFindByClassName(el, className) dot.gif{
InBlock.gif
InBlock.gif  
var i, tmp;
InBlock.gif
InBlock.gif  
if (el.className == className)
InBlock.gif    
return el;
InBlock.gif
InBlock.gif  
// Search for a descendant element assigned the given class.
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
for (i = 0; i < el.childNodes.length; i++dot.gif{
InBlock.gif    tmp 
= winFindByClassName(el.childNodes[i], className);
InBlock.gif    
if (tmp != null)
InBlock.gif      
return tmp;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
return null;
ExpandedBlockEnd.gif}

None.gif
None.gif
//=============================================================================
None.gif//
 Initialization code.
None.gif//
=============================================================================
None.gif

None.gif
var winList = new Array();
None.gif
var winCtrl = new Object();
None.gif
ExpandedBlockStart.gifContractedBlock.gif
function winInit() dot.gif{
InBlock.gif
InBlock.gif  
var elList;
InBlock.gif
InBlock.gif  
// Initialize window control object.
InBlock.gif

InBlock.gif  winCtrl.maxzIndex                        
=   0;
InBlock.gif  winCtrl.resizeCornerSize                 
=  16;
InBlock.gif  winCtrl.minimizedTextWidth               
= 100;
InBlock.gif  winCtrl.inactiveFrameBackgroundColor     
= "#c0c0c0";
InBlock.gif  winCtrl.inactiveFrameBorderColor         
= "#f0f0f0 #505050 #404040 #e0e0e0";
InBlock.gif  winCtrl.inactiveTitleBarColor            
= "#808080";
InBlock.gif  winCtrl.inactiveTitleTextColor           
= "#c0c0c0";
InBlock.gif  winCtrl.inactiveClientAreaBorderColor    
= "#404040 #e0e0e0 #f0f0f0 #505050";
InBlock.gif  winCtrl.inactiveClientAreaScrollbarColor 
= "";
InBlock.gif  winCtrl.inMoveDrag                       
= false;
InBlock.gif  winCtrl.inResizeDrag                     
= false;
InBlock.gif
InBlock.gif  
// Initialize windows and build list.
InBlock.gif

InBlock.gif  elList 
= document.getElementsByTagName("DIV");
InBlock.gif  
for (var i = 0; i < elList.length; i++)
InBlock.gif    
if (elList[i].className == "window")
InBlock.gif      winList[elList[i].id] 
= new Window(elList[i]);
ExpandedBlockEnd.gif}

None.gif
None.gifwindow.onload 
= winInit;  // run initialization code after page loads.
None.gif

None.gif
//]]>
下载 /Files/yknb/JavaScriptDemo.rar

转载于:https://www.cnblogs.com/yknb/archive/2006/09/22/512015.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值