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.
Server code:<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>
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |