0

I want to open a pdf file when page is getting loaded (onload), I done it through calling javascript function on onload action ,I can open a pdf in adobe reader ,but issue is I got new Blank browser-window in addition to adobe file(opened in adobe not in browser)

<html>
<script type="text/javascript">
    function windoeOpen() {
        var myWindow = window.open(" ", "windowname", "width=200, height=100");
        myWindow.location.href = "file:///F:/pdf2.pdf";
    }
</script>

<body onload="windoeOpen()">
  <code>
  ........
 </code>
</body>

</html>

please give me suggestion how can I close the additional browser blank window.

Note:

but if I open pdf in browser ,it works fine(opened in browser as expected) no addition blank browser.

Radhika
  • 3
  • 1
  • 4
  • 1
    possible duplicate of [How to trigger a file download when clicking an html button or javascript](http://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript) – Shanimal Sep 01 '15 at 21:53
  • if you're doing `window.location.href`, you don't need a `window.open` – Sushil Sep 01 '15 at 21:59
  • Thank you for giving correct solution!it works now only adobe file is opened ,no addition blank window – Radhika Sep 01 '15 at 22:13

1 Answers1

1

You just need to specify window.location.href like this:

JavaScript:

<script type="text/javascript">
    function windoeOpen()
    {
        window.location.href = "file:///F:/pdf2.pdf";
    }
</script>

HTML:

<body onload ="windoeOpen()">

  • I got another issue ,if I open file in browser ,it loads in same window not opening in new window, – Radhika Sep 02 '15 at 14:01