1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help! How Can I Make A Pop Up Window with download link and javascript

Discussion in 'HTML & JavaScript' started by Empire007, Jul 8, 2013.

  1. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    Okay, i am not quite good in coding myself, but i have tried to use google to find if i could have an anwser for this but no luck, maybe i am not putting in the right keywords.

    I made a html page, and i want to put a download link and a script, so once the user click the download button image, The download will begin and the script will open in another tab. i dont know how to do it, please your help would be appretiated
     
  2. Lyscer

    Lyscer Junior Member

    Joined:
    Jun 29, 2012
    Messages:
    109
    Likes Received:
    46
    Occupation:
    Software Engineer
    I'm not quite sure what you are referring to with the term "and the script will open in another tab". From a scripting perspective I don't think it is possible to control opening a new tab vs new window because that is a setting in the browser that determines how links are opened.

    If I am over simplifying this then please clarify and I will revise my answer. For your download link you will have something like the following (I chose a random image from google for demonstration):

    javascript_method_to_run would be defined in the <head> of the html
    Code:
    <head>
        <script type="text/javascript">
            function javascript_method_to_run(){
                // Code to do something . . .
    
                // Open a new window to execute code/script on that page
                window.open('http://www.new_window_domain.com', '_blank');
            }
       </script>
    
    This would go in the <body>

    Code:
    <a onclick="javascript_method_to_run();" href="http://www.linktothedownload.com">
        <img src="http://fbdownloader.com/images/download_button.png" alt="Download [FILE_NAME]" title="Download [FILE_NAME] />
    </a>