title: How to trigger the browser to save file via CGI?
body: <p>I have the following hidden form:</p>
  
  <pre><code>&lt;form id='export_svg_container_single_form'
        action='exportSVG.pl'
        method='post'
        target='_blank'
        style='display:none;'&gt;
    &lt;input type='text'
           id='export_svg_container_single_form_data'
           name='export_svg_data'
           style=';' /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The <code>export_svg_data</code> field value gets populated with an SVG document before form submission.</p>
  
  <p>When submitted, this acts on the following simple CGI script, written in Perl:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use CGI;
  use CGI::Pretty qw/:standard/;
  
  my $val = param('export_svg_data');
  print "Content-Type:image/svg+xml\n";
  print "Content-Disposition: inline\n";
  print "Content-Description: File to download\n\n";
  print $val;
  </code></pre>
  
  <p>When submitted, the hidden form also opens a new tab and displays (in this case) an SVG document. The end user can then save the window to a file.</p>
  
  <p>Instead, on submitting the form, what I would like to do is have the browser automatically open a <strong>Save</strong> or <strong>Save As</strong> dialog box so that the user can pick a filename and save the document, instead of rendering the SVG within the browser window. </p>
  
  <p>How might I do this with JavaScript or the appropriate changes to the CGI script? (I'd like to leave the parent form page untouched, i.e. open a new tab or window, if that is required.) Thanks for your advice.</p>
  
  <p>To clarify again, I am looking for a solution which brings up the <strong>Save</strong> dialog box. I do not want the script to determine the filename and to save it somewhere random, without any user intervention.</p>