I can think of a couple of different approaches, for the non-javascript approach rather than trying to write to two frames at the same time, you can look at it from a different angle, have the log frame simply refresh periodically, and have the write_log method write the logs to a file.
sub makeframeset { # create document frameset. top area for ui # bottom area for XMLRPC trace my $self = self_url; print header, frameset({-border => "1", -rows => "1*,1*", cols => "*"}, frame({-name => 'main', -src => "$self?run=page"}), frame({-name => 'log', -src => "$self?run=log"}) ), end_html; } sub write_log { open( OUT, ">>/tmp/logfile" ); print OUT "$_<br>" for @_; close( OUT ); } my $run = param("run"); if ($run eq 'log') { print header, '<meta http-equiv="refresh" content="10">'; open( IN, "/tmp/logfile" ); print <IN>; close(IN); } elsif ($run eq 'page') { write_content('Main Area'); write_content("<a href='self_url()'>Simulate Run</a>"); } else { write_content("running..."); write_log("foo"); }
The alternative would require a little javascript...
<script language="JavaScript"><!-- function write_log(msg) { parent.log.document.write(msg + '<br>'); } //--></script>
Then you could do something like this:
print "This is content area\n"; print "write_content('This is a log message');";
Note that there are some other problems to overcome with the code you posted (for example, in the elsif($run eq 'page' ) section, you call write_content() twice, but write_content() provides headers and document wrappers, which means you will get two sets of content-type headers, two sets of document tags, etc).
| We're not surrounded, we're in a target-rich environment! |
|---|
In reply to Re: Outputting to 2 HTML frames from 1 CGI
by jasonk
in thread Outputting to 2 HTML frames from 1 CGI
by spatterson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |