Open PDF in new tab with Javascript

I am trying to open a PDF sitting on our sever in a new window when a button is clicked. I am using the window.open() function in javascript to try and achieve this. When I click the button, a new tab opens, but it is an about:blank tab. Here is my ASP.NET markup for the button:

<asp:Button ID="BTN_OpenPDF" runat="server" Text='<%#Eval("TicketNum").ToString()%>' OnClientClick='openPDF(this);'/>

And here is the javascript code that I am trying to execute:

function openPDF(element) {
        var text = element.value;

        window.open('Z:/Ticket Scans/' + text + '.pdf');
    }

I am dynamically setting the text of the button to retrieve the ticket number and this works fine. When I step through the debugger I can tell that the file path is correct, but the pdf still does not open.

I am using ASP.NET, C#, and Chrome.

Edit: From doing some research I believe that this may be a Chrome security issue. When using an anchor tag instead of the Javascript:

<a target="-blank" href="z:\Ticket Scans\<%#Eval("TicketNum") %>.pdf></a>

I get an error in the debugger saying: Now allowed to load local resource. But when I run the app in IE11 it works perfectly fine.

Answers


would like to create this icon for permanent use.

Try adjusting command for launching chrome at properties of launcher icon , adding --allow-file-access-from-files flag

/path/to/chrome --allow-file-access-from-files


Need Your Help

Dynamic associative Array - list, count, sum, min, max

php function dynamic multidimensional-array associative-array

I've got an array with about 40 keys. I'd like to have a small function that returns a summary array.

result isn't correct when use reportprogress

c# winforms backgroundworker

I have listview with items add static and have text value sequence : 1,2,3,4,5,6