Hi I need to open my view in a new window on this button click but it opens in the same window. This is the syntax I'm using.
<button id="btnPrintReport" onclick="location.href='@Url.Action("LoadReports", "DashBoard", new { target="_blank" })'" >Print</button>
Have I missed anything? Thanks.
Try window.open
to open link in a new tab
onclick="window.open('@Url.Action("LoadReports", "DashBoard", new { target="_blank" })')"
DEMO
As far as I know, <button>
won't work with target
. Same goes for input type="button" ... />
elements:
You need to use an anchor and style it with css as a button
<a [email protected]("LoadReports", "DashBoard") id="aPrintReport" target="_blank" class="button">Print</a>
<!--taken from http://stackoverflow.com/questions/2187008/styling-an-anchor-tag-to-look-like-a-submit-button-->
.button {
text-decoration: none; font: menu;
display: inline-block; padding: 2px 8px;
background: ButtonFace; color: ButtonText;
border-style: solid; border-width: 2px;
border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
}
.button:active {
border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With