Click here to Skip to main content
15,498,859 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The hyperlink created with below code in .aspx page of project does not open a PDF file when clicking on "click to open file" on Edge and Chrome browser (It works good on IE browser). The content shows blocked when opened in the new TAB.

<a href="javascript:void(0)" id="A0" visible="true" runat="server" style="text-decoration: underline;"
                                            onclick="navigateTo('`Myfolder\\Myfile.pdf');">click to open file</a>

function navigateTo(subLink) {

    var servername = '<%= fileServer %>';
    var link1 = '\\\\' + servername + subLink.replace("`", "");, '_blank');

    return false;

Need to create same hyperlink that works on Edge and Chrome as well.

What I have tried:

I tried to modify above tag but still it is not working on Edge and Chrome.
Updated 2-Jun-21 3:54am
gacar 1-Jun-21 14:32pm    
'`Myfolder\\Myfile.pdf' Does this sign ` have to be there?
Member 15224382 2-Jun-21 4:36am    
Yes, the sign ` exist in " navigateTo('`Myfolder\\Myfile.pdf'); " and is working good on IE browser.
Richard Deeming 2-Jun-21 8:20am    
Either there's a problem in your navigateTo method, which you haven't shown; or the file doesn't exist at the URL you're trying to open; or you're trying to open a file: URL from an http(s): page.
Richard Deeming 2-Jun-21 8:32am    
"Bumping" your question by adding irrelevant comments isn't going to get you an answer any quicker. You need to provide some proper details. Show the definition of your navigateTo method, and clarify how the page is loaded and where the PDF file is stored.
Member 15224382 2-Jun-21 9:19am    
Thanks for correcting me . The file is stored on network file server and when user click on the hyperlink the the network file server name along with file location on the file server is navigated to open the PDF file in new tab. So variable link1 has full file path of the file server. Hyperlink works good on IE.

1 solution

And there you go - once you show the definition of navigateTo, the problem becomes clear. 😊

All modern web browsers forbid a page served via http: or https: from navigating to a local file. This is a security measure, and cannot be bypassed.

The code works in Internet Explorer, because it's ancient, and is terribly insecure. Even Microsoft agree that IE should not be used[^].

You will need to create a handler on your site which reads the PDF file directly from the server and returns it to the user, so that the navigation is to an http(s): URL instead of a file: URL. That means your application will need to run as a user with sufficient permissions to read the files.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900