Forms and file downloads with JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tevatron
    New Member
    • Dec 2006
    • 1

    Forms and file downloads with JavaScript

    Hi, I have the following combo box source code:

    Code:
    <script type="text/javascript">
    function go1(){
    if (document.selecter1.select1.options[document.selecter1.select1.selectedIndex].value != "none") {
    location = document.selecter1.select1.options[document.selecter1.select1.selectedIndex].value
    		}
    	}
    //-->
    </script>
    <script type="text/javascript">
    <!--
    document.write('<form name="selecter1"><select name="select1" size=1>');
    document.write('<option value=none>Select');
    document.write('<option value=none>--------------------');
    document.write('<option value="FILE.PDF">File');
    document.write('<option value="FILE.PDF">File');
    document.write('<option value="FILE.PDF">File');
    document.write('</select>');
    document.write('  <input type="button" value="Go" onclick="go1()">');
    document.write('</form>');
    // end hiding contents -->
    </script>
    How can I make the form ask the users if they want to open the selected file with a program or download it instead of opening the file in the web browser?

    Thank you in advance!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Set the content-disposition header, or set an unknown content type to get the browser to ask the user to download the file, or you could even zip the file to "force" a download.

    Comment

    Working...