关闭窗口,弹出新窗口的问题.

liuyjcel 2009-03-26 03:40:41
A.aspx页面是一个弹出的模态页面,在页面中我加入 <base target="_self">的,为什么我关闭页面是,还要弹出一个新的页面呢 ?
关闭代码 如下:
Response.Write("<script>window.opener=null;window.close();</script>");
...全文
236 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
灿烂阳光168 2009-03-26
  • 打赏
  • 举报
回复
学习中
阿非 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 CutBug 的回复:]
引用 11 楼 Sandy945 的回复:
你应该 知道 两段代码的区别吧



C# code protected void btn_Click(object sender, EventArgs e)
{
Response.Write("<script>window.opener=null;window.close();</script>");
}


问一下,模态对话框window.opener能取得父框口对象吗?
[/Quote]

当然不能了 ,你也不是不知道showModalDialog 的第二个参数。
只是楼主的代码 那么写,我引用 一下 ,来说明是可以不开新窗口关闭的。
erytbc 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 CutBug 的回复:]
引用 11 楼 Sandy945 的回复:
你应该 知道 两段代码的区别吧



C# code protected void btn_Click(object sender, EventArgs e)
{
Response.Write("<script>window.opener=null;window.close();</script>");
}


问一下,模态对话框window.opener能取得父框口对象吗?
[/Quote]
明显不能。
CutBug 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 Sandy945 的回复:]
你应该 知道 两段代码的区别吧
[/Quote]

 protected void btn_Click(object sender, EventArgs e)
{
Response.Write("<script>window.opener=null;window.close();</script>");
}

问一下,模态对话框window.opener能取得父框口对象吗?
CutBug 2009-03-26
  • 打赏
  • 举报
回复
onclick里用location.reload()是可以的,指定location.href是不行的
阿非 2009-03-26
  • 打赏
  • 举报
回复
你应该 知道 两段代码的区别吧
CutBug 2009-03-26
  • 打赏
  • 举报
回复
你试试在2.htm把button改成这样
<input type="button" onclick="location.href='3.htm'"/>
CutBug 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Sandy945 的回复:]
引用 2 楼 CutBug 的回复:
<base target="_self">只对超级链接有效,
button的onclick事件里刷新页面还是会打开新页面的


你试过么?
[/Quote]
你很幽默,我没试过会说吗?
1.htm
<script>
window.showModalDialog("2.htm");
</script>
2.htm
<html>
<head>
<base target="_self"/>
</head>
<body>
<form target="_self" action="2.htm" method="post" >
<input type="submit" value="刷新" />
</form>

</body>
</html>
阿非 2009-03-26
  • 打赏
  • 举报
回复



parent.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="parent.aspx.cs" Inherits="parent" %>

<!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>
<body>
<form id="form1" runat="server">
<input type="button" value="open" onclick="showModalDialog('ModalDialog.aspx')" />
</form>
</body>
</html>




ModalDialog.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModalDialog.aspx.cs" Inherits="ModalDialog" %>

<!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>
<base target="_self"></base>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btn" runat="server" Text="postback" OnClick="btn_Click" />
</div>
</form>
</body>
</html>



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ModalDialog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btn_Click(object sender, EventArgs e)
{
Response.Write("<script>window.opener=null;window.close();</script>");
}
}


试完,回来再说  
benbirdar 2009-03-26
  • 打赏
  • 举报
回复
在两个页面都加上<base target="_self">
阿非 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 CutBug 的回复:]
<base target="_self">只对超级链接有效,
button的onclick事件里刷新页面还是会打开新页面的
[/Quote]

你试过么?
CutBug 2009-03-26
  • 打赏
  • 举报
回复
嘴哥臭鼬 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 CutBug 的回复:]
<base target="_self">只对超级链接有效,
button的onclick事件里刷新页面还是会打开新页面的
[/Quote]
那把链接的click事件放在link里好了
liuyjcel 2009-03-26
  • 打赏
  • 举报
回复
那应该怎么处理?
CutBug 2009-03-26
  • 打赏
  • 举报
回复
<base target="_self">只对超级链接有效,
button的onclick事件里刷新页面还是会打开新页面的
阿非 2009-03-26
  • 打赏
  • 举报
回复
你加在那里了? 是<head></head>之间么

62,268

社区成员

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

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

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

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