1、最基本的弹出窗口代码
<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html') //打开一个窗口
-->
</SCRIPT>
javascripts代码应该放在两个<SCRIPT>...<>SCRIPT>之间,<!-- -->是为了解决一些低版本浏览器的兼容性。
运行结果:打开一个窗口
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=n o, status=no')
-->
</SCRIPT>
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为允许;
3、最大化弹出窗口
<html>
<head>
<title>window.open最大化 </title>
</head>
<body>
<script language="javascript">
<!--
function openTest()
{
var ww = window.screen.availwidth - 10; //可用宽度减去10
var hh = window.screen.availheight - 60; //可用高度减去60
window.open("test.htm", "", "toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=yes,top=0,left=0,width=" + ww + ",height=" + hh);
}
-->
</script>
<input id="Button" type="button" value="最大化新窗口" onclick="openTest()" />
</body>
</html>
4、弹出窗口并居中
<html>
<head>
<title>window.open居中 </title>
</head>
<body>
<script language="javascript">
<!--
function openTest(url, name, iWidth, iHeight)
{
var url;
//转向网页的地址;
var name;
//网页名称,可为空;
var iWidth;
//弹出窗口的宽度;
var iHeight;
//弹出窗口的高度;
var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
//获得窗口的垂直位置;
var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
//获得窗口的水平位置;
window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}
-->
</script>
<input id="Button" type="button" value="居中新窗口" onclick="openTest('test.htm','居中新窗口',400,400)" />
</body>
</html>
5、弹出子窗口并返回值
<html>
<head>
<title>window.open返回值父窗口</title>
<style type="text/css">
#father
{
width: 500px;
height: 100px;
}
</style>
<script type="text/javascript">
function openTest()
{
window.open('test.htm')
}
</script>
</head>
<body>
<input id="father" type="text" /><br />
<br />
<input id="Button" type="button" value="打开子窗口" onclick="openTest()" /><br />
</body>
</html>
<html>
<head>
<title>window.open返回值子窗口</title>
<style type="text/css">
#Text1
{
height: 100px;
width: 500px;
}
</style>
<script type="text/javascript">
function openerTest()
{
window.opener.document.getElementById("father").value = Text1.value;
window.close()
}
</script>
</head>
<body>
<p>
<input id="Text1" type="text" /><br />
<br />
<input id="Button" type="button" value="关闭并返回值" onclick="openerTest()" /></p>
</body>
</html>
分享到:
相关推荐
对window.open进行封装, 使其更好用, 且更兼容, 很多人说window.open不兼容,其实不是, 因为不能直接执行, 必须通过用户手动触发才行;看代码: 代码如下 var openWindow = function(url, options) { var str = ""; ...
弹出窗口,并且弹出窗口要求最大化处理,window.open打开的窗口获取到焦点
扩展window.open方法,使得window.open时针对相同的URL地址非打开新窗口,而是仅仅激活已存在窗口,另外,此激活不会刷新页面,不会丢失页面上已存在的数据
Window.open ('page.html') 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。用单引号和双引号都可以,只是不要混用。 这一段代码...
Web开发中的window.open父子窗口传值问题 部署在tomcat中进行
主要讲解了如何利用window.open打开新窗口,和打开新窗口时的一些参数的设置,很实用的。
windows.open这个是JavaScript函数,但是在应用起来的时候总会遇到比较多的麻烦,因为参数非常多,用法也非常的多
window.open()对于各浏览器兼容情况
window.showModalDialog以及window.open用法简介
关于window.open的一些特性,一些你经常不注意的,值的一看啊
NULL 博文链接:https://shawnfree.iteye.com/blog/598885
window.open打开新窗口,不被拦截的方法
一、window.open()支持环境: 二、基本语法: 三、示例: 四、各项参数
window.open()参数大全,window.open()参数大全,window.open()参数大全。
window.open使用方法以及参数说明一、window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二、基本语法: window.open(pageURL,name,parameters) 其中: pageURL 为子窗口路径 name 为子窗口...
这段示例代码不但能在父窗口页面test.html中执行被打开的新窗口页面test-open.html中的代码,还可以随意调用其中的内容,甚至还可以在父窗口页面中使新窗口页面置顶(显示在最前面)。 代码已在当前的chrome , fire...
[removed] var timer var winOpen function IfWindowClosed() { if (winOpen.closed == true) { document.fm_Info.txtValue.value=”child closed” window.clearInterval(timer) } } [removed] <input type=b
window.open参数详解.txt
javascript 打开页面window.location和window.open的区别.docx
弹出窗口,并且弹出窗口要求最大化处理,window.open打开的窗口获取到焦点