I want to open a page in new tab of browser on button click.
I have searched a lot on google but i couldn\'t find anything.
Here is my button.
Take care to reset target, otherwise all other calls like Response.Redirect
will open in a new tab, which might be not what you want.
<asp:LinkButton OnClientClick="openInNewTab();" .../>
In javaScript:
<script type="text/javascript">
function openInNewTab() {
window.document.forms[0].target = '_blank';
setTimeout(function () { window.document.forms[0].target = ''; }, 0);
}
</script>
Why not just call window.open straight from OnClick?
<asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry" OnClick="window.open('New.aspx')" />
try this rather than redirect...
Response.Write("<script>");
Response.Write("window.open('ClickPicture.aspx','_blank')");
Response.Write("</script>");
A simple solution:
<a href="https://www.google.com" target="_blank">
<button type="button">Open new tab</button>
</a>