JavaWeb - JavaScript中Window对象

来源:互联网 发布:数据库应用领域 编辑:程序博客网 时间:2024/05/21 06:19

打开网页

<html><head><title></title><script language="javascript">function fun(thisurl){window.open(thisurl) ;}</script></head><body onLoad="fun('index.html')"></body></html>

控制窗口大小

<html><head><title></title><script language="javascript">function fun(thisurl){window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;}</script></head><body onLoad="fun('index.html')"></body></html>

Demo

<html><head><title></title><script language="javascript">function fun(thisurl){window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;}</script></head><body><form action="" method="post" name="myform">网址:<select name="url" onChange="fun(this.value)"><option value="index.html">index</option><option value="3.html">3</option>  </select></form></body></html>

确认提示按钮

<html><head><title></title><script language="javascript">function fun(){if(window.confirm("确认删除?")){alert("您选择的是'是'!") ;} else {alert("您选择的是'否'!") ;}}</script></head><body><a href="#" onclick="fun()">删除邮件</a></body></html>

重定向

<html><head><title></title><script language="javascript">function fun(thisurl){window.location = thisurl ;// 重定向}</script></head><body>网站:<select name="url" onChange="fun(this.value)"><option value="#">== 请选择要浏览的站点 ==</option><option value="http://www.baidu.com">百度</option><option value="http://blog.csdn.net/imwangjiping">wjp博客</option>  </select></body></html>

子窗口调用父窗口(子窗口操作父窗口中的一些对象)

父窗口<html><head><title></title><script language="javascript">function fun(thisurl){window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;}</script></head><body><input type="button" value="打开" onClick="fun('3.html')" ></body></html>
子窗口<html><head><title></title><script language="javascript">function closeWin(){window.close() ;// 关闭窗口}window.opener.location.reload() ;// 刷新页面</script></head><body><h3><a href="#" onclick="closeWin()" >关闭</a></h3></body></html>

子窗口调用父窗口(子窗口操作父窗口中的一些对象)Demo

父窗口<html><head><title></title><script language="javascript">function fun(thisurl){window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;}</script></head><body><form name="parentform"><input type="button" value="选择信息" onclick="fun('3.html')" ><br>选择的结果:<input type="text" name="result"></form></body></html>
子窗口<html><head><title></title><script language="javascript">function returnValue(){var city = document.myform.city.value ;// 取出当前选择好的信息var doc = window.opener.document ;// 取得父窗口文档doc.parentform.result.value = city ;// 设置新内容window.close() ;}</script></head><body><form name="myform">选择:<select name="city"><option value="北京">北京</option><option value="上海">上海</option><option value="深圳">深圳</option><option value="广州">广州</option><option value="天津">天津</option></select><input type="button" value="返回" onclick="returnValue()"></form></body></html>

 

0 0
原创粉丝点击