Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-19 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found