damian has asked for the wisdom of the Perl Monks concerning the following question:

hi guys, i know javascript can write text or html tags in your html document with a document.write(); is the a way that a javascript could call a cgi script that will print out an html tag? the cgi script reads external html tags from a file, and the javascript's job is to call this cgi script to print the html tag that the cgi script prints. thanks in advance.

Replies are listed 'Best First'.
(crazyinsomniac) Re: javascript to execute perl cgi script
by crazyinsomniac (Prior) on Aug 25, 2000 at 09:49 UTC
    Hi,

    athomason is absolutely right.
    I would like to point out thought that there is 'client side javascript'(in your browser) and 'server side javascript'(runs on the server).

    Server Side JavaScript is something the people from Netscape cooked up, and you need special software(LiveWire i think) to run it. As far as I know, it never really took off, seeing how there were better alternatives(perl).

    Anyway, an alternative to SSI(Server Side Includes) is to use frames, or layers. You could use regular frames or a combination of IE's inline frames( <IFrame SRC='path_to_your_.cgi'> ) and Netscape specific <layer src='path_to_your_.cgi'>.

    For IE you could also use a <div src='path_to_your_.cgi'> tag, but netscape won't recognize the src attribute.

    Anyway, check out www.blooberry.com for any of your future HTML questions. It's an excellent reference with HTML version and browser support/peculiarity info....

     

    "cRaZy is co01, but sometimes cRaZy is cRaZy".
                                                          - crazyinsomniac
Re: javascript to execute perl cgi script
by athomason (Curate) on Aug 25, 2000 at 09:26 UTC
    I don't think Javascript is what you really want here. It's barely compatible among browsers, and people who don't have/want it are left out. Anyhow, what you're doing sounds more conducive to server-side includes (with the <!--#exec > tag) than Javascript. Or you could just do it all in CGI. SSI and Perl will both work with any browser, anytime, anywhere, provided you can use them on your server. And writing full pages with CGI.pm is really quite simple once you figure it out. You'll save yourself a lot of pain in the long run, and in this case, the short run too.
RE: javascript to execute perl cgi script
by t0mas (Priest) on Aug 25, 2000 at 10:23 UTC
    A bit out of Perl context, but anyway... You could do it, but as others has pointed out, SSI is a better way to go. I've used the following technique to do it:

    1. You'll need frames, and you'll need to stay in the same domain or javascript signing/tainting will stop you.
    2. Frame 1 uses javascript (frame2.document.location) to load a html document generated by a cgi script.
    3. The cgi generated document has a form with a <textarea> which contains the html tags that you want to print.
    4. Grab the contents of the textarea and do what you like with them.

    A bit messy but it works. You can have a look at a toy that vroom graciously granted me to have on my home node (yes, I actually asked). It uses Javascript to automagically surf the PM site. It grabs links from another window and makes the window change location.

    /brother t0mas
Re: javascript to execute perl cgi script
by damian (Beadle) on Aug 25, 2000 at 10:15 UTC
    thanks guys i think will use crazyinsomniac's advice.