Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi Monks,

I have 3 different report output options in a web browser (csv download, screen display, and pdf), but after displaying the report, I'd like the server to send some javascript to the browser that calls my javascript function showWait(0); which closes my "Please wait" window.

<script> function getReport3(){ showWait(1); if(document.getElementById('outputTypeScreen').checked){ document.reports.setAttribute("target", 'report_window +'); var results=window.open('','report_window','scrollbars +=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status= +no'); }else{document.reports.setAttribute('target','_self');} document.reports.submit(); } </script> ... <form method="post" id='reports' name='reports'> <input type='hidden' name='rm' value='reports_getReport'> ... <input type='radio' name='outputType' id='outputTypeDownload' value='d +ownload'><label for='outputTypeDownload'>CSV Download</label> <input type='radio' name='outputType' id='outputTypeScreen' value='scr +een' ><label for='outputTypeScreen'>Screen</label> <input type='radio' name='outputType' id='outputTypePDF' value='pdf' > +<label for='outputTypePDF'>PDF</label> <input type='button' value='Search' onclick='getReport3()' > </form>
Server code:

use CGI ':standard'; use CGI ':cgi-lib'; use CGI::Carp qw(fatalsToBrowser); use Switch; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use Template; use Template::Stash; use strict; use warnings; ... sub reports_getReport{ my $self = shift; my $q = $self->query; ... switch($outputType){ case 'download'{ my $data=csvReport($report); #take the data and convert to com +ma delimited $self->header_props(-type => 'application/octet-stream +', -attachment => 'report.csv'); $self->header_add(-script=>{-type=>'text/javascript',-code=>' +alert("hi there"); showWait(0); '}); return $data; } case 'screen'{#this works!!! my $html=screenReport($report); return $html; } case 'pdf'{ my $data=getReport($report);#$data is a pdf stream $self->header_props(-type => 'application/pdf', -attac +hment => 'report.pdf'); $self->header_add(-script=>{-type=>'text/javascript',-code=>' +alert("hi there"); showWait(0); '}); return $data; } else{} } } sub screenReport{ my $report=shift; my $html=''; $html.=' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <script type="text/javascript" src="/forms/layout/sorttable.js"></scri +pt> <script type="text/javascript">var opener=this.window.opener;opener.sh +owWait(0);</script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body>'; ... $html.='</body></html>'; return $html; }

My 'screen' case works fine, but I'm not able to get my 'download' and 'pdf' cases to run any javascript. Otherwise, everything works like they're supposed to. Is this even possible?


In reply to CGI attachment + javascript? by ksublondie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (4)
    As of 2014-04-17 01:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (437 votes), past polls