转自:http://blog.youkuaiyun.com/kaifeixiongdi/article/details/6648046
Tag:如何用C#在Asp.net中实现打开新网页而不关闭当前页
方法一:
Respose.Write("<script language='javascript'>window.open('"+ url +"');</script>");
(打开简洁窗口):
Respose.Write("<script language='javascript'>window.open('" + url + "','','resizable=1,scrollbars=0,status=1,menubar=no,toolbar=no,location=no, menu=no');</script>");
1.Response.Redirect("XXX.aspx",true)——直接转向新的页面,原窗口被代替;
2. Response.Write("<script>window.open('XXX.aspx','_blank')</script>")——原窗口保留,另外新增一个新页面;
3.Response.Write("<script>window.location='XXX.aspx'</script>")——打开新的页面,原窗口被代替;
4.Server.Transfer("XXX.aspx")——打开新的页面;
5.Response.Write("<script>window.showModelessDialog('XXX.aspx')</script>")——原窗口保留,以对话框形式打开新窗口;
6.Response.Write("<script>window.showModelDialog('XXX.aspx')</script>")——对话框形式打开新窗口,原窗口被代替;
ASP.NET打开新窗口方法一:
Response.Write("<script language=/"javascript/">window.open('aaa.aspx','新窗口,/"toolbar=yes,location=no,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes/");</script>");
这种方式代码每次是生成在页面最顶端
ASP.NET打开新窗口方法二:
string strScript = "";
strScript += "<script language=/"javascript/">/n";
strScript += "window.open('aaa.aspx','新窗口,/"toolbar=yes,location=no,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes/");/n";
strScript += "location.href='index.html';";
strScript += "</script>";
bool b = ((Page)System.Web.HttpContext.Current.Handler).IsStartupScriptRegistered("PopUp");
if (!b)
{
((Page)System.Web.HttpContext.Current.Handler).RegisterStartupScript("PopUp",strScript);
}
这种方式是在页面中生成JAVASCRIPT代码
注意:如果输出JAVSSCRIPT语句后,页面又用Response.Redirect跳转到其他页,JAVASCRIPT将不会出现.
实现弹出窗口和跳转同时必须都在JAVASCRIPT语句里,
这是我测试的,不知道大家有没有什么不同的意见??
asp.net中打开新窗口的多种方法
1.Response.Redirect("XXX.aspx",true)——直接转向新的页面,原窗口被代替;
2. Response.Write("<script>window.open(XXX.aspx'',''_blank'')</script>")——原窗口保留,另外新增一个新页面;
3.Response.Write("<script>window.location=XXX.aspx''</script>")——打开新的页面,原窗口被代替;
4.Server.Transfer("XXX.aspx")——打开新的页面;
5.Response.Write("<script>window.showModelessDialog(XXX.aspx'')</script>")——原窗口保留,以对话框形式打开新窗口;
6.Response.Write("<script>window.showModalDialog(XXX.aspx'')</script>")——对话框形式打开新窗口,原窗口被代替;
"_blank " Load the linked document into a new blank window. This window is not named.
"_parent " Load the linked document into the immediate parent of the document the link is in.
"_search " Load the linked document into the browser 's search pane. Available in Internet Explorer 5 or later.
"_self " Load the linked document into the same window the link was clicked in (the active window).
"_top " Load the linked document into the topmost window.