PDA

View Full Version : Conditional SSI possible?


patrik
09-13-2002, 06:47 PM
Has anyone had any luck using javascript to conditionally load a Server Side Include?

It would seem quite simple, but this is causing me to pull my hair out in frustration!

<script language="JavaScript">
if (self==parent)
document.write('<!--#include virtual="../../HeaderNavAlt.html" -->');
</script>

What this is supposed to do is to confirm the page is not in a frameset, and if so then insert HeaderNavAlt.html (containing a scripted navigation set). Behaviour of the "parent" file is bizarre - sometimes the SSI file mostly works, sometimes when I open the parent file, the reference ("#include virtual = etc") to the SSI is magically gone, and the actual code from the SSI file has been inserted en toto - but all wonky! It sometimes looks almost as if the #include statement is being executed no matter what - as if it weren't part of a conditional statement!

Am I having problems because the inserted file has scripts?
Does writing the SSI call itself in javascript screw things up?
...and what about Naomi?! (sorry...)

Thanks again to anyone who cares to offer some aid!

brothercake
09-13-2002, 06:54 PM
SSI takes place on the server, where javascript takes place in the browsers.

Suppose that the included file your calling looks like this

<b>hello world</b>

then going

document.write('<!--#include virtual="../../HeaderNavAlt.html" -->');

would be the same as

document.write('<b>hello world</b>');

It works in a simple situation like that, but if the included file is complex you'll get problems. If it contains any apostrophes then it will generate errors.

Make sense?

patrik
09-13-2002, 07:19 PM
Make sense?
--------------

Yes. I was missing the forest for the trees.

So by having scripts in the included file, I was basically saying something along the lines of:

document.write("<script>document.write("blah,blah");</script>);

which as some of the scripts were rather complex, would rapidly degenerate to chaos.
DOH!

Time to change gears..

Thanks much!