我想在按钮点击的新浏览器选项卡中打开一个页面.
我在谷歌搜索了很多,但我找不到任何东西.
这是我的按钮.
<asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry" OnClick="btnNewEntry_Click" />
protected void btnNewEntry_Click(object sender, EventArgs e)
{
Response.Redirect("New.aspx");
}
Run Code Online (Sandbox Code Playgroud)
你能帮帮我怎样才能做到这一点吗?
Ari*_*ion 33
你可以用window.open.像这样:
protected void btnNewEntry_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(),"OpenWindow","window.open('YourURL','_newtab');",true);
}
Run Code Online (Sandbox Code Playgroud)
小智 7
为什么不直接从OnClick调用window.open?
<asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry" OnClick="window.open('New.aspx')" />
Run Code Online (Sandbox Code Playgroud)
请务必重置target,否则所有其他类似的呼叫Response.Redirect都将在新选项卡中打开,这可能不是您想要的。
<asp:LinkButton OnClientClick="openInNewTab();" .../>
Run Code Online (Sandbox Code Playgroud)
在javaScript中:
<script type="text/javascript">
function openInNewTab() {
window.document.forms[0].target = '_blank';
setTimeout(function () { window.document.forms[0].target = ''; }, 0);
}
</script>
Run Code Online (Sandbox Code Playgroud)