PDF File Download and Redirect With One Click Using HTML and JavaScript


PDF File Download and Redirect With One Click Using HTML and JavaScript

  • The anchor tag can be used to download files or to redirect to another web page.
  • The href attribute creates a hyperlink to file.
  • The 'download' attribute specifies that the target(the files specified in the href attribute) will be downloaded when a user clicks on hyperlink.

Here is the simple code to download and redirect the pdf file.

HTML CODE

<a href="filename.pdf" onlclick=" redirectPage('filename.pdf'); "  download>
    Click here to download
</a>



JAVASCRIPT CODE

<script type = "text/javascript" >
    function redirectPage(url)
        {
            window.open(url);
        }
</script>

                                                
                                                                                          - Happy Coding

Comments

Popular posts from this blog

Simple HTML Form Elements For Registration Page Example

Writing data to a file using Python

Validation Code For Phone Number Using preg_match() in Php