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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.