0

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?

craig2020
  • 321
  • 1
  • 6
  • 12

1 Answers1

1

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>
Hany Habib
  • 1,377
  • 1
  • 10
  • 19