关闭子页面刷新父级页面

skydhx 2014-09-11 01:39:15
现在要求实现一个功能, a页面 服务器按钮
string strScript = "<script language=javascript>window.open('WebForm3.aspx','newwindow','width=600,height=600,top=50, left=200')</script>";
Response.Write(strScript);

打开 WebForm3.aspx 页面,

当关闭 WebForm3 页面 如何刷新 a 页面, WebForm3 页面关闭直接点击右上角 X 关闭的,怎么触发刷新a页面
...全文
709 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq1746178060 2014-09-13
  • 打赏
  • 举报
回复
使用JavaScript关闭子窗口刷新父窗口示例 //设置打开新窗口事件 <a href="#" onClick="window.open('Default2.aspx','','width=200,height=150');"><strong> <span style="font-size: 9pt;text-decoration:none" >添加数据</span></strong></a> //GridView控件设置显示内容 protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]); con.Open(); SqlDataAdapter ada = new SqlDataAdapter("select * from tb_23",con); DataSet ds = new DataSet(); ada.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); }//CodeGo.net/ //关闭子窗口刷新父窗口 protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]); con.Open(); SqlCommand com = new SqlCommand("insert into tb_23(name,number)values('" + TextBox1.Text + "','" + TextBox2.Text + "')",con); com.ExecuteNonQuery(); Response.Write("<script language=javascript>alert('添加成功!');opener.location.reload();window.close();</script>"); }
天空丶蒋 2014-09-12
  • 打赏
  • 举报
回复
<script > window.opener.location.href = window.opener.location.href; if (window.opener.progressWindow) { window.opener.progressWindow.close(); } window.close(); </script>
骑猪看海 2014-09-11
  • 打赏
  • 举报
回复
抱歉,上面的代码会死循环,请放在方法中点击加载吧
骑猪看海 2014-09-11
  • 打赏
  • 举报
回复
简单的定义个showModalDialog既可 window.showModalDialog("http://baidu.com/","dialogWidth=200px;dialogHeight=100px"); location.reload();
白云任去留 2014-09-11
  • 打赏
  • 举报
回复
zhengnan2012 2014-09-11
  • 打赏
  • 举报
回复
引用 10 楼 Sky_Dhx 的回复:
[quote=引用 7 楼 zhengnan2012 的回复:] bs的系统我感觉要实现楼主这个效果很麻烦.本来bs系统就是单个页面单个页面,不向winfrom一样. 你这个类似于消息推送, 什么长连接,什么轮询,反正对关闭一个页面来说不是很必要啊.
头疼,依然不行,在 子页面 按钮时间里面 写的 Response.Write("<script>parent.location.reload(); </script>"); 根本不行, 而且弹出框还死循环的关不掉[/quote] 别引用我,这个方法我没有提供.我建议就是不做这种.或者是用上面两种成本很高的方式,长连接,轮询.
rayyu1989 2014-09-11
  • 打赏
  • 举报
回复
我都给你弹alert了 你不会把alert替换成 window.location.href吗???
skydhx 2014-09-11
  • 打赏
  • 举报
回复
引用 17 楼 rayyu1989 的回复:
给你兼容了下 firefox也支持了
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<a href="javascript:;" id="a">TEST</a>
<script type="text/javascript">
(function(){
	var handle,dispose=function(){
		window.clearInterval(handle);
	};
	var child;
	document.getElementById("a").onclick = function(){
		dispose();
		child = window.open('http://www.zhaixiaowai.com/JSCompress/','test','width=800,height=400,top=100,left=200');
		handle = window.setInterval(function(){
			var hasclose;
			try{
				hasclose=!child||!child.top||child.closed;
			}catch(ex){hasclose=true;}
			if(hasclose){
				dispose();
				child=null;
				alert("child has been closed");
			}
		},1000);
	};
})();
</script>
</body>
</html>
thank you ,刚用了, 父级其实没有刷新的,数据灭有实时,我在试试其他方法
rayyu1989 2014-09-11
  • 打赏
  • 举报
回复
给你兼容了下 firefox也支持了
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<a href="javascript:;" id="a">TEST</a>
<script type="text/javascript">
(function(){
	var handle,dispose=function(){
		window.clearInterval(handle);
	};
	var child;
	document.getElementById("a").onclick = function(){
		dispose();
		child = window.open('http://www.zhaixiaowai.com/JSCompress/','test','width=800,height=400,top=100,left=200');
		handle = window.setInterval(function(){
			var hasclose;
			try{
				hasclose=!child||!child.top||child.closed;
			}catch(ex){hasclose=true;}
			if(hasclose){
				dispose();
				child=null;
				alert("child has been closed");
			}
		},1000);
	};
})();
</script>
</body>
</html>
rayyu1989 2014-09-11
  • 打赏
  • 举报
回复
按你的需求 你完全可以 变更了数据的时候设置个cookie,parent页面 open时候轮询cookie,和这段代码原理相同
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<a href="javascript:;" id="a">TEST</a>
<script type="text/javascript">
(function(){
	var handle,dispose=function(){
		window.clearInterval(handle);
	};
	var child;
	document.getElementById("a").onclick = function(){
		dispose();
		child = window.open('http://www.zhaixiaowai.com/JSCompress/','test','width=500,height=400,top=100,left=200');
		handle = window.setInterval(function(){
			var hasclose;
			try{
				hasclose=!child||!child.top;
			}catch(ex){hasclose=true;}
			if(hasclose){
				dispose();
				alert("child has been closed");
			}
		},1000);
	};
})();
</script>
</body>
</html>
rayyu1989 2014-09-11
  • 打赏
  • 举报
回复
sorry 没测ie 我看看
skydhx 2014-09-11
  • 打赏
  • 举报
回复
引用 13 楼 rayyu1989 的回复:
本地已测试过,你看看哪里复制错了,我这就是个纯静态的页面 你如果套到net里注意下
我用 ie11测试是报错,,,JavaScript runtime error: The interface is unknown. 火狐没有, 但是 这个 刷新页面了吗》? 我这刷新的目的是,有可能页面打开i了, 主页面会有数据增加减少,当你关闭子页面了,父级页面数据就没有实时, 所以要实现一次刷新的效果
rayyu1989 2014-09-11
  • 打赏
  • 举报
回复
本地已测试过,你看看哪里复制错了,我这就是个纯静态的页面 你如果套到net里注意下
skydhx 2014-09-11
  • 打赏
  • 举报
回复
引用 11 楼 rayyu1989 的回复:
备用解决方案
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<a href="javascript:;" id="a">TEST</a>
<script type="text/javascript">
(function(){
	var handle,dispose=function(){
		window.clearInterval(handle);
	};
	var child;
	document.getElementById("a").onclick = function(){
		dispose();
		child = window.open('http://www.zhaixiaowai.com/JSCompress/','test','width=500,height=400,top=100,left=200');
		handle = window.setInterval(function(){
			if(!child||!child.top){
				dispose();
				alert("child has been closed");
			}
		},1000);
	};
})();
</script>
</body>
</html>
报错,,,JavaScript runtime error: The interface is unknown.
rayyu1989 2014-09-11
  • 打赏
  • 举报
回复
备用解决方案
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<a href="javascript:;" id="a">TEST</a>
<script type="text/javascript">
(function(){
	var handle,dispose=function(){
		window.clearInterval(handle);
	};
	var child;
	document.getElementById("a").onclick = function(){
		dispose();
		child = window.open('http://www.zhaixiaowai.com/JSCompress/','test','width=500,height=400,top=100,left=200');
		handle = window.setInterval(function(){
			if(!child||!child.top){
				dispose();
				alert("child has been closed");
			}
		},1000);
	};
})();
</script>
</body>
</html>
skydhx 2014-09-11
  • 打赏
  • 举报
回复
引用 7 楼 zhengnan2012 的回复:
bs的系统我感觉要实现楼主这个效果很麻烦.本来bs系统就是单个页面单个页面,不向winfrom一样. 你这个类似于消息推送, 什么长连接,什么轮询,反正对关闭一个页面来说不是很必要啊.
头疼,依然不行,在 子页面 按钮时间里面 写的 Response.Write("<script>parent.location.reload(); </script>"); 根本不行, 而且弹出框还死循环的关不掉
rayyu1989 2014-09-11
  • 打赏
  • 举报
回复
window.onbeforeunload
fcylovehbb 2014-09-11
  • 打赏
  • 举报
回复
关闭了直接跳到你的父页面不行,还要去刷一下
zhengnan2012 2014-09-11
  • 打赏
  • 举报
回复
bs的系统我感觉要实现楼主这个效果很麻烦.本来bs系统就是单个页面单个页面,不向winfrom一样. 你这个类似于消息推送, 什么长连接,什么轮询,反正对关闭一个页面来说不是很必要啊.
lai6257469 2014-09-11
  • 打赏
  • 举报
回复
Response.Write("<script>parent.location.reload(); </script>");
加载更多回复(5)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧