Redirect to homepage after download starts.

3 replies
  • WEB DESIGN
  • |
Hi,

I'm having a problem about this can anyone help how to do this? Thanks in advance.

Regards,
Matt
#download #homepage #redirect #starts
  • Profile picture of the author TheWorker
    This is an idea that may work, but may not be the best solution.

    You may need to redirect to home page first, and then initiate (via javascript) the download from the home page.

    e.g. say this is your download link (I am making assumptions here)
    http://yoursite.com/download_doc.php?doc=myebook.pdf
    http 302 redirect to
    http://yoursite.com/home.php?download=myebook.pdf

    On home.php, you would detect the download=myebook.pdf, and insert javascript to trigger the download. I am not sure if a popup blocker would interfere here.
    {{ DiscussionBoard.errors[5068996].message }}
    • Profile picture of the author TheWorker
      Here is a better example using Javascript. You may want to convert to JQuery for browser compatability.

      The first link calls the javascript to click the 2nd link. The 2nd link is hidden, but when clicked (by the javascript), opens the target document in a new tab or window. The first link continues as normal, and goes to the home page. Job done.

      <html>
      <head>
      <script>
      function trigger_download() {
      document.getElementById('downloadme').click();
      }
      </script>
      </head>
      <body>
      <a href="home.htm" onclick="trigger_download();">Download!</a>
      <a id=downloadme target=_blank href="http://yourdomain.com/ebook.pdf" style="display: none;">thedoc</a>
      </body>
      </html>

      PS: You could also investigate the use of javascript window.open(...)
      {{ DiscussionBoard.errors[5069351].message }}
      • Profile picture of the author Matt Baker
        Originally Posted by TheWorker View Post

        Here is a better example using Javascript. You may want to convert to JQuery for browser compatability.

        The first link calls the javascript to click the 2nd link. The 2nd link is hidden, but when clicked (by the javascript), opens the target document in a new tab or window. The first link continues as normal, and goes to the home page. Job done.

        <html>
        <head>
        <script>
        function trigger_download() {
        document.getElementById('downloadme').click();
        }
        </script>
        </head>
        <body>
        <a href="home.htm" onclick="trigger_download();">Download!</a>
        <a id=downloadme target=_blank href="http://yourdomain.com/ebook.pdf" style="display: none;">thedoc</a>
        </body>
        </html>

        PS: You could also investigate the use of javascript window.open(...)
        Thanks I really appreciate this one.. it's working
        Signature

        {{ DiscussionBoard.errors[5081325].message }}

Trending Topics