Open local pdf file from a local html file

别来无恙 提交于 2019-12-12 03:36:45

问题


I am working in a simple html application which is expected to run in IE8 and above, Chrome browsers. The html application is launched from a desktop shortcut and it will open in the default browser as shown below,

Note: The path of the html file is local path.

To avoid security issues related in loading scripts, I have added the "Mark of the Web" in my application and it works great.

<!DOCTYPE html>
<!-- saved from url=(0016)http://localhost -->
<html lang="en">
<head>

The issue I am facing now is, opening a help file (.pdf) which is in the same location as html file throws "Access Denied" error.

Options I have tried:

a. Referred the help file path in the HTML tab and it did not work

<a href="help.pdf" class="help pull-right" target="_blank">Help</a>

a. On the above link click , set the window.location as shown below,

window.location = 'help.pdf' //access denied error

I have also referred several answers in stackoverflow say for example: How can I create a link to a local file on a locally-run web page? but none of them worked for me.

Expectation:

Open a local pdf file from a link in local html file. Is it possible? Let me know your suggestions. Thanks.


回答1:


try this out, just change location of ur pdf file into below href ..., better put thm in a seperate folder ie the html and pdf file that u wanna download.

<html>
<body>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<a href="#" id="someID" >continue</a>
<script>
$('a#someID').attr({target: '_blank', 
                    href  : 'http://math.hws.edu/eck/cs124/downloads/javanotes6-linked.pdf'});
  
  // give the location of ur file... in href
</script>
</body>
</html>


来源:https://stackoverflow.com/questions/35615627/open-local-pdf-file-from-a-local-html-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!