Forum Moderators: open

Message Too Old, No Replies

How to get Javascript to write an <!--include virtual... line?

Trying to pass Javascript info to a Perl CGI script

         

MichaelBluejay

4:50 am on May 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Okay, so I have this Javascript that beautifully fills up a sidebar with exactly as many ads as will fit, depending on the height of the page. But the client says on his computer it takes a while for the ads to appear, slowly, one at a time. He's got a modern computer but the ads load almost instantaneously on my old Pentium III/500MHz.

So I was thinking, why not have a Perl script write out all the ads? All I'd need was a way to pass the height of the page to the Perl script.

And that's where I'm stuck.

I tried using JavaScript to write out an include line, like so:

<script type="text/javascript">
testHeight='1000';
stringToWrite = '<' + '!--#include virtual="/filler.cgi?' +testHeight+ '"-->';
document.write(stringToWrite);
</script>

But no output appears when I load the page. Yes, I have the Add-Handler line in my <.htaccess> file and other SSI's work in general. It's a big site and all the pages are HTML, not dynamically generated, but we do use lots of SSI.

Notice I split up stringToWrite, because if I iclude the < sign next to the! sign then the server parser just executes the include right away, rather than waiting for the string to be drawn.

I'm guessing I can't do it this way, because by the time JavaScript has written the SSI line, the server has already washed its hands of the file and any SSI directives it contains.

If so, the question then becomes: Assuming I already got the page height with JavaScript, how can I pass that page height to my Perl CGI script?

Thanks for your help.

Bernard Marx

8:59 am on May 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'd have to reload the page, sending the height as a query string parameter.
The need for a page reload makes it probably not worth it.