Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Is it possible to output to an open web page?

by lawlist (Initiate)
on Apr 28, 2014 at 17:55 UTC ( #1084156=perlquestion: print w/replies, xml ) Need Help??
lawlist has asked for the wisdom of the Perl Monks concerning the following question:

Instead of loading an entirely new web page (header | middle | footer) with the output, I am wondering whether it is possible to include the output to the same webpage that is already open. Perhaps with SSI -- where there is a header | middle | footer, the output could go into the middle section?
<!--#include file="header.include.shtml" --> <hr COLOR="#CCCCCC" size=1 NOSHADE> <!--#exec cgi="/cgi-bin/test.cgi"--> <!--#include file="footer.include.shtml" -->
#!/usr/bin/perl use CGI qw(:standard); print "Content-type: text/html\n\n"; my $dir = '/home/lawlist/www'; my $query = new CGI; my $name = $query->param('name'); my $file = $dir . "/" . $name; if ($name) { open(FILE,'/home/lawlist/www/header.include.shtml') and print <FILE> +; close FILE; } opendir(DIR, $dir) or die $!; while (my $file = readdir(DIR)) { next unless (-f "$dir/$file"); next unless ($file =~ m/\.txt|.el$/); print '<a href="/cgi-bin/test.cgi?name=' . $file . '">' . $file . "< +/a>" . "<br>" . "\n\n"; } closedir(DIR); if ($name) { open (DATA, $file) or return $self->print_json_error($self->language +('ERR_CANNOT_OPEN', $file->{name}, $!)); read (DATA, my $file, -s DATA); close DATA; print "<br>\n\n<br>\n\n"; print '<pre class="brush: lisp">' . "\n\n" . $file . "\n" . '</pre> +'; print "\n\n<br>\n"; open(FILE,'/home/lawlist/www/footer.include.shtml') and print <FILE> +; close FILE; } exit 0;

Replies are listed 'Best First'.
Re: Is it possible to output to an open web page?
by InfiniteSilence (Curate) on Apr 28, 2014 at 18:19 UTC

    ...I am wondering whether it is possible to include the output to the same webpage that is already open...

    Of course, you can use JavaScript on the client-side to fetch additional content and update your web page without reloading the entire page. If the client's browser has JavaScript turned off, of course, that will not work.

    Your other option is to use frames, which I think is deprecated and not recommended even if it is not.

    Celebrate Intellectual Diversity

Re: Is it possible to output to an open web page?
by amon (Beadle) on Apr 28, 2014 at 18:23 UTC

    No, websites don't work like that. SSI or CGI scripts assemble a whole page and then send it to the browser which then displays this page. However, you can use JavaScript on your web site. This JS can then make a request to your server when a link is clicked, and replace content in the displayed page by the content from the response.

    Such a JavaScript request to the server is called “AJAX”. JavaScript libraries like “jQuery” can help you make the request and insert the response into the page.

Re: Is it possible to output to an open web page?
by zentara (Archbishop) on Apr 28, 2014 at 18:32 UTC
    That is becoming how the most advanced sites are doing it now. Javascript and Ajax requests, each going to a predefined division in the browser window, usually call a div.

    But if you you want to avoid javascript, you can use Frames or iFrames. See my website for example. Look at the index html you get, and see the Frames I define.

    Then in outputing from a cgi script, you can write for instance:

    <form method=post target=_top $secure_server_address$cgi_directory/admin.cgi>
    where your target is where you want it to go... top, side, bottom, left right?

    P.S. I believe Frames are being deprecated in favor of iFrames, so there probably is a better way than plain Frames.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Please see also as well as Why Frames Suck...OK this is old stuff ;-) but...

      Update: added little correction (in italics)...

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

        Thank you all very much. I had seen something like that occurring on certain websites, but did not know the names of what I was seeing. I'll look into the options mentioned in this thread and spend some time creating a few working examples to help me better understand how it all gets put together. I'm greatly appreciative for you all having taken the time to steer me in the right direction! :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1084156]
Approved by Old_Gray_Bear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2017-03-26 23:17 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (315 votes). Check out past polls.