CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
JavaScript excuting cgi

 



ypwong
Deleted

Jan 13, 2000, 2:56 AM

Post #1 of 3 (1210 views)
JavaScript excuting cgi Can't Post

Sorry about all the questions....
can I execution a script using javascript?
[ex]
can I do something like this...
<HTML>.....
<Body onload = "execute run.pl">
I want to execute a script as soon as the webpage finish loading....and WITHOUT changing the contents of the current page...
is there someway to do that?


Jasmine
Administrator / Moderator

Jan 13, 2000, 3:25 AM

Post #2 of 3 (1210 views)
Re: JavaScript excuting cgi [In reply to] Can't Post

Is there a particular reason you want to use JavaScript? Server Side Includes (SSI) is ideal for that purpose.

I've checked all of my JavaScript books and did not find any commands that will run a cgi script.

If you don't have SSI enabled on your server, you can cheat by using an image tag like this:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


<IMG SRC="/cgi-bin/run.pl" HEIGHT=3 WIDTH=3>
</pre><HR></BLOCKQUOTE>

Then, you can set up your run.pl to something like this:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

$|=1;

print "Content-Type: text/html\n\n";
print "http://yourdomain.com/transparent.gif";
# the rest of your code here
</pre><HR></BLOCKQUOTE>

The $|=1 will flush the Perl buffer, which will display the image without waiting for the rest of your program to finish what it's doing.

The print "Content-Type: text/html\n\n"; line will tell the server and browser what kind of content follows.

The print "http://yourdomain.com/transparent.gif"; directs the program to display a transparent image. Make sure you upload a transparent image to the location you're using in this line.

While <IMG SRC> sample above uses a HEIGHT and WIDTH of 3 and 3 each, you can use whatever size you wish. It's recommended not to use 1x1 pixel images anymore - WebTV visitors cannot properly display 1x1 images yet.)

I'm sorry I couldn't find a JavaScript solution for you. But for future reference, it may be wise to seek different solutions before you turn to any JavaScript-dependent solution. Many people turn JavaScript off in their browsers, mainly to avoid those annoying pop-up windows that are predominant in "free" web sites.

Best of luck!


[This message has been edited by Jasmine (edited 01-13-2000).]


brian.hayes
User

Jan 13, 2000, 7:28 PM

Post #3 of 3 (1210 views)
Re: JavaScript excuting cgi [In reply to] Can't Post

Well here it is...


I just tested this against my web server..


This will output the text of a cgi file or an image print of a cgi, but not both. Well I could not figure out how to do both. So mabee this will help..

This is I.E......tested only...
Take a look at the SRC="TO CGI/PERL" below...
<SCRIPT LANGUAGE=javascript>
document.write('<IFRAME WIDTH="500" HEIGHT="100"');
document.write('SCROLLING="no" FRAMEBORDER="0" FRAMESPACING="0" MARGINHEIGHT="0" ');
document.write('MARGINWIDTH="0" BORDER="0" HSPACE="0" VSPACE="0" ');
document.write('ALIGN="center" SRC="http://www.devitcom.com/cgi-bin/test/meta.cgi"">');
document.write('</IFRAME>');

</SCRIPT>


My CGI script is:
The commented out is the image test....If this was uncomented I would only get the image but not the text.

#!/usr/local/bin/perl -w
$|=1;
$img = "/home/vhost/www.devitcom.com/image/button3.gif";
print "Content-Type: text/html\n\n";

## If you want an image the while is important.
#open IMG,$img or die "$!";
# while (<IMG> )
#
# { print "$_";}
#close IMG or die "$!";
print "Testing this\n\n";

exit;

This will also not work in Netscape 4.5, what I used to test with..."Sorry"..

Hope this helps...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives