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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.