craig2020
craig2020

Reputation: 381

opening Url.Action in new tab

I have a button which opens a URL action, which contains a .PDF file. I need this button to open the PDF file in a new tab when clicked. Although currently it opens in the same tab.

Current code:

<button target="_blank" onclick="location.href='@Url.Action("OpenPDF", "FlaggedSurveys", new { id = ViewBag.CompletedCamp } )'" type="button" class="btn btn-primary">
            <span class="glyphicon glyphicon-plus" aria-hidden="true" target="_blank"></span> Open Survey PDF
        </button>

I have also tried fromtarget"_blank":

<button formtarget="_blank" onclick="location.href='@Url.Action("OpenPDF", "FlaggedSurveys", new { id = ViewBag.CompletedCamp } )'" type="button" class="btn btn-primary">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Open Survey PDF
        </button>

Can someone tell me how to get the first Button opening on a new tab please?

Upvotes: 0

Views: 1599

Answers (1)

Hany Habib
Hany Habib

Reputation: 1405

For it to work you can try :

<button formtarget="_blank" onclick="window.open('@Url.Action("OpenPDF", "FlaggedSurveys", new { id = ViewBag.CompletedCamp } )')" type="button" class="btn btn-primary"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Open Survey PDF </button>

a working example:

<button formtarget="_blank" onclick="window.open('www.google.com')" type="button" class="btn btn-primary"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Open Survey PDF </button>

Upvotes: 1

Related Questions