我在在a.aspx中弹出b.aspx窗口,然后关闭b.aspx时刷新a.aspx
但是情况不是很妙,求大神帮助。 a.aspx中调用showModalDialog("b.aspx", window, 'location:1;dialogHeight:300px;’);
b.aspx中两种情况
1、OnClientClick="javascript:self.close();window.dialogArguments.location=a.aspx';"
在IE中可以使用,FF中不会刷新父页面
2、OnClientClick="javascript:window.opener.location.reload();window.close()" />
在IE中不可以使用window.opener.location.reload(),在FF中可以
但是情况不是很妙,求大神帮助。 a.aspx中调用showModalDialog("b.aspx", window, 'location:1;dialogHeight:300px;’);
b.aspx中两种情况
1、OnClientClick="javascript:self.close();window.dialogArguments.location=a.aspx';"
在IE中可以使用,FF中不会刷新父页面
2、OnClientClick="javascript:window.opener.location.reload();window.close()" />
在IE中不可以使用window.opener.location.reload(),在FF中可以
我忘记说了
我在b.aspx中有操作数据库然后刷新b.aspx的按钮我刚开始也是楼上这么写的
但是他只再窗口中刷新了b.aspx。然后也没有关闭。a.aspx也没有反应
function f()
{
var a= showModalDialog("b.aspx", window, 'location:1;dialogHeight:300px;’);
//刷新本页面
//在弹出的页面未关闭之前,程序不会执行到以下这一句,而是会停留在上一句.
document.location.href=document.location.href;
}如果你希望弹出的页面在一定的条件才刷新父页面,那么,上面的程序可以修改为
var a = showModalDialog(...);
if(a == "1")
{
//刷新
}如何得到a这个变量?你只需要在弹出的页面中,输出脚本(不管前台或后台)returnValue=1;self.close();即可
下面是ie8,ff正确执行的完整的测试代码,你照着拷贝就行了,
a.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["cmd"] != null) b.Attributes.Add("style", "background:red");
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body id="b" runat="server">
<form id="form1" runat="server">
<input type="button" onclick="window.showModalDialog('b.aspx',window)" value="打开窗口" /> </form>
</body>
</html>
b.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="关闭" OnClientClick="window.dialogArguments.location.href='a.aspx?cmd=' + Date.parse(new Date());top.close();return false;" />
</form>
</body>
</html>
昨天网被雨下坏了
我反复的实验发现在IE中随便怎么样都是可以
在FF中有问题
因为b.aspx中有个按钮操作数据库
操作完之后刷新b.aspx
如果在b.aspx页面没有点击按钮刷新b.aspx页面
那么关闭后会刷新a.aspx
如果b.aspx中点击了按钮刷新了b.aspx重新绑定了数据
那么点关闭它只刷新了b.aspx,而且也没有关闭窗口顺便再想问下
b.aspx页面cs文件中的page_load方法为什么只有第一次访问b.aspx才会执行?
其他时候都不会执行、、
分怎么追加
谢谢各位啦
缓存的问题showModalDialog("b.aspx?t=" + Date.parse(new Date()), window, 'location:1;dialogHeight:300px;’);即可避免
例子
http://dotnet.aspx.cc/article/00000000-0000-0000-0000-00000000000f/read.aspx
采用
top.dialogArguments.location.href='a.aspx?cmd=' + Date.parse(new Date());top.close();return false;
a.aspx<input type="button" onclick="window.showModalDialog('c.aspx',window)" value="打开窗口" />c.aspx<%@ Page Language="C#" %><!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 runat="server">
<title></title>
</head><frameset cols="0,*">
<frame src=""></frame>
<frame src="b.aspx?tmp=<%=System.Guid.NewGuid().ToString() %>"></frame>
</frameset>
</html>
b.aspx
<%@ Page Language="C#" EnableViewState="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button2_Click(object sender, EventArgs e)
{
Response.Write("xxx");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
<asp:Button ID="Button1" runat="server" Text="关闭" OnClientClick="window.top.dialogArguments.location.href='a.aspx?cmd=' + Date.parse(new Date());top.close();return false;" />
</form>
</body>
</html>
至于我这个点击b.aspx中的按钮后就不会刷新父页面然后关闭窗口
我想是不是因为我点按钮刷新b.aspx后充值了他的父页面之类的
你按钮里加一个JS . JS的内容是调用前台JS .
前台JS 这么写 b.aspx页面里写
function CatalogEdit()
{
window.opener.refresh(); //调用父级方法
window.opener=null;
window.close();关闭 b.aspx页面里写
}
a.aspx页面
function refresh()
{
this.location = this.location; //刷新
}
您真的像老师一样
楼上的
IE中window.opener会报错
结贴了
非常感谢大家