[ back to toc ]

insert javascript into header of cgi script

Date: 2002/04/25 12:49

Q:
Ok I want to insert a javascript into the header of a cgi script but i do
not know the format to do so. could u help plz? :
Here is the part of the script:

print "Content-type: text/html\nPragma: no-cache\n\n";
print "<html><HEAD><title></title></HEAD><BODY BGCOLOR=#000000
TEXT=#FFFFFF>\n";
&getform;
if (&getoldfile) {
&gettime;
&printform;
if ($form{'message'} ne "") { &printnewfile; }
else { &printnoframes; }
}
else
{
print "The room you entered <I>$form{'room'}</I> does not exist.<BR>\n";
print "Tell the server administrator to check the file:
<I>$filepath$form{'room'}$filext</I>\n";
}
print "</font></body></html>\n";
exit(0);

AND HERE IS THE SCRIPT I WANNA INSERT BETWEEN HEAD - /HEAD:
<SCRIPT>
<! function ScreenIt(url,name,parm){
if(url.indexOf("adpopup")!=-1) return false;
if(url.indexOf("go2net")!=-1) return false;
if(url.indexOf("?")!=-1) return false;
return window.Xopen(url,name,parm);
}
window.Xopen=window.open;
window.open=ScreenIt;
//-->
</SCRIPT>
COULD U HELP PLZ.. THANKS!
A:
You can not insert a JavaScript into a CGI script. There is no such thing
as header of a CGI script. What you actually want is (I assume) to insert
a JavaScript code into the header of the HTML file that is sent by the CGI
script as a response. In this way, what you need is:

print "Content-type: text/html\nPragma: no-cache\n\n";
print <<END;
<html><HEAD>
<SCRIPT>
<!function ScreenIt(url,name,parm){
if(url.indexOf("adpopup")!=-1) return false;
if(url.indexOf("go2net")!=-1) return false;
if(url.indexOf("?")!=-1) return false;
return window.Xopen(url,name,parm);
}
window.Xopen=window.open;
window.open=ScreenIt;
//-->
</SCRIPT>
<title></title></HEAD><BODY BGCOLOR=#000000 TEXT=#FFFFFF>
END
&getform;
if (&getoldfile) {
&gettime;
&printform;
if ($form{'message'} ne "") { &printnewfile; }
else { &printnoframes; }
}
else
{
print "The room you entered <I>$form{'room'}</I> does not exist.<BR>\n";
print "Tell the server administrator to check the file:
<I>$filepath$form{'room'}$filext</I>\n";
}
print "</font></body></html>\n";
exit(0);

Regards,
Peter

[ back to toc ]