Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

CGI attachment + javascript?

by ksublondie (Friar)
on May 17, 2012 at 22:40 UTC ( #971186=perlquestion: print w/replies, xml ) Need Help??
ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

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'','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" ""> <html xmlns="" 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; +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?

Replies are listed 'Best First'.
Re: CGI attachment + javascript?
by Anonymous Monk on May 18, 2012 at 03:23 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://971186]
Approved by ww
and the monastery is silent...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-02-27 02:28 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (376 votes). Check out past polls.