弹出窗口并向父页面返回值的两种常用方法
2017-11-16 18:02
423 查看
方法一:使用showModalDialog方法
新建文件lyh.html
输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
<input type="button" onclick="show('lyhshow.html')" value="弹出窗口"><br><br><br>返回值:
<input type="text" id="returnvalue">
<script language="javascript">
function show(math)
{
var val= showModalDialog(math,"true", "dialogWidth:300px;dialogHeight:250px;status:no;help:no;");
if(!val)
{
return;
}
else
{
document.all.returnvalue.value=val;
}
}
</script>
</body>
</html>
新建文件lyhshow.html
输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
请输入:<input type="text" id="txtValue" value=""><br><br><br>
<input type="button" onclick="ReturnValue()" value="返回输入值">
<script language="javascript">
function ReturnValue()
{
window.returnValue=document.all.txtValue.value;
window.close();
}
</script>
</body>
</html>
方法二:用window.open弹出窗口
新建文件lyh2.html
输入
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
<input type="button" onclick="show('lyhshow2.html')" value="弹出窗口"><br><br><br>返回值:
<input type="text" id="returnvalue">
<script language="javascript">
<!--
function show(math)
{
window.open (math,'newwindow','height=250,width=300,top=300,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
//写成一行
}
-->
</script>
</body>
</html>
新建文件lyhshow2.html
输入
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
请输入:<input type="text" id="txtValue" value=""><br><br><br>
<input type="button" onclick="ReturnValue()" value="返回输入值">
<script language="javascript">
function ReturnValue()
{
window.opener.document.all.returnvalue.value=document.all.txtValue.value;
window.close();
}
/*优化
窗口关闭时生效*/
window.onbeforeunload = onbeforeunload_handler;
function onbeforeunload_handler(){
window.opener.doc
a01c
ument.all.returnvalue.value=document.all.txtValue.value;
}
</script>
</body>
</html>
新建文件lyh.html
输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
<input type="button" onclick="show('lyhshow.html')" value="弹出窗口"><br><br><br>返回值:
<input type="text" id="returnvalue">
<script language="javascript">
function show(math)
{
var val= showModalDialog(math,"true", "dialogWidth:300px;dialogHeight:250px;status:no;help:no;");
if(!val)
{
return;
}
else
{
document.all.returnvalue.value=val;
}
}
</script>
</body>
</html>
新建文件lyhshow.html
输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
请输入:<input type="text" id="txtValue" value=""><br><br><br>
<input type="button" onclick="ReturnValue()" value="返回输入值">
<script language="javascript">
function ReturnValue()
{
window.returnValue=document.all.txtValue.value;
window.close();
}
</script>
</body>
</html>
方法二:用window.open弹出窗口
新建文件lyh2.html
输入
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
<input type="button" onclick="show('lyhshow2.html')" value="弹出窗口"><br><br><br>返回值:
<input type="text" id="returnvalue">
<script language="javascript">
<!--
function show(math)
{
window.open (math,'newwindow','height=250,width=300,top=300,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
//写成一行
}
-->
</script>
</body>
</html>
新建文件lyhshow2.html
输入
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>来自Eric空间</title>
</head>
<body>
请输入:<input type="text" id="txtValue" value=""><br><br><br>
<input type="button" onclick="ReturnValue()" value="返回输入值">
<script language="javascript">
function ReturnValue()
{
window.opener.document.all.returnvalue.value=document.all.txtValue.value;
window.close();
}
/*优化
窗口关闭时生效*/
window.onbeforeunload = onbeforeunload_handler;
function onbeforeunload_handler(){
window.opener.doc
a01c
ument.all.returnvalue.value=document.all.txtValue.value;
}
</script>
</body>
</html>
相关文章推荐
- 弹出窗口并向父页面返回值的两种常用方法
- Js 弹出框 返回值的两种常用方法
- 单击页面按钮,弹出浮动窗口的两种方法
- IE无法屏蔽的弹出页面的方法!Response.Redirect 打开新窗口的两种方法
- JS控制弹出新页面窗口位置和大小的方法
- JavaScript页面刷新与弹出窗口问题解决方法
- javascript页面刷新与弹出窗口问题解决方法
- JS在用户离开页面时提示信息&常用的弹出窗口用法
- JavaScript页面刷新与弹出窗口问题的解决方法
- easyui dialog 子窗口jsp(被弹出窗口)调用父jsp页面方法操作父jsp
- 使用POST方式弹出窗口的两种方法示例介绍
- JavaScript页面刷新与弹出窗口问题解决方法
- .net 嵌入在框架页面内弹出新窗口方法介绍
- 弹出dialog的两种方法; 以及在关闭的时候刷新父窗体; 有时候同样的东西用这种窗口不起作用另外一种运行ok
- jquery 触发a标签点击事件,弹出页面;不被浏览器屏蔽拦截的打开窗口的方法
- 打印Web页面局部内容的两种常用方法
- JavaScript页面刷新与弹出窗口问题解决方法
- JavaScript页面刷新与弹出窗口问题解决方法
- Javascript刷新页面的几种方法(页面刷新与弹出窗口问题解决方法)