当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 一组常用的弹出窗口用法总结

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 一组常用的弹出窗口用法总结


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-04   浏览: 380 ::
收藏到网摘: n/a

一组常用的弹出窗口用法
以下代码集合常用的弹出窗口用法. 
1、最基本的弹出窗口代码
以下是引用片段:
<SCRIPT LANGUAGE="javascript">  
<!--  
window.open (’page.html’)  
-->  
</SCRIPT>  
代码放在<SCRIPT LANGUAGE="javascript">标签和</script>之间。 
<!-- 和 -->是对一些版本低的浏览器起作用。 
window.open (’page.html’) 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。用单引号和双引号都可以,只是不要混用。 
这一段代码可以加入HTML的任意位置,<head>和</head>之间可以,<body>间</body>也可以,越前越早执行,尤其是页面代码长,又想使页面早点弹出就尽量往前放。 

2、经过设置后的弹出窗口
定制这个弹出的窗口的外观,尺寸大小,弹出的位置以适应该页面的具体情况。 
以下是引用片段:
<SCRIPT LANGUAGE="javascript">  
<!--  
window.open (’page.html’, ’newwindow’, ’height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no’)  
//写成一行  
-->  
</SCRIPT>  
参数解释: 
以下是引用片段:
<SCRIPT LANGUAGE="javascript"> js脚本开始;  
window.open 弹出新窗口的命令;  
’page.html’ 弹出窗口的文件名;  
’newwindow’ 弹出窗口的名字(不是文件名),非必须,可用空’’代替;  
height=100 窗口高度;  
width=400 窗口宽度;  
top=0 窗口距离屏幕上方的象素值;  
left=0 窗口距离屏幕左侧的象素值;  
toolbar=no 是否显示工具栏,yes为显示;  
menubar,scrollbars 表示菜单栏和滚动栏。  
resizable=no 是否允许改变窗口大小,yes为允许;  
location=no 是否显示地址栏,yes为允许;  
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;  
</SCRIPT> 
js脚本结束 

3、用函数控制弹出窗口
完整的代码示范 
以下是引用片段:
<html>  
<head>  
<script LANGUAGE="javascript">  
<!--  
function openwin() { window.open ("page.html", "newwindow", "height=100, width=400, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")  
//写成一行  
}  
//-->  
</script>  
</head>  
<body onload="openwin()">  
...任意的页面内容...  
</body>  
</html>  

这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。 
怎么调用呢? 
方法一:<body onload="openwin()"> 浏览器读页面时弹出窗口; 
方法二:<body onunload="openwin()"> 浏览器离开页面时弹出窗口; 

方法三:用一个连接调用: 
<a href="#" onclick="openwin()">打开一个窗口</a> 
注意:使用的“#”是虚连接。 
方法四:用一个按钮调用: 
<input type="button" onclick="openwin()" value="打开窗口">