PDA

View Full Version : Writing a conditional SSI



PFTW
Jun 27th, 2007, 09:41 PM
Hi all, I'm new to this site and new to javascript programming. I'm having a problem with something that I think should be simple. Basically have a page that I need to use in two sites. The page has several Server Side Includes (SSIs) that I want to be displayed as an iframe in one site (mysite1), but not the other (mysite2). So I've built the simple "if" statement which works:



<script type="text/javascript" language="javascript">
if ("http://mysite2.htm"!=top.location){
document.write("hello")
}
</script>


This will write "Hello" in the site that I want it to appear (mysite1) and it won't write "hello" in the other (mysite1) so I know it works.

My problem is when I try to replace the "Hello" string with the string for the SSI. First I tried the direct approach (or at least what I thought was the direct approach):



<script type="text/javascript" language="javascript">
if ("http://mysite2.htm"!=top.location){
document.write("<!--#include virtual=\"/includes/top.inc\"-->")
}
</script>


Notice I used the escape character "\" in front of each quote within the string, but that didn't work, I got this error:


Active Server Pages error 'ASP 0126'

Include file not found

/training/tech_and_bp_website/adp.html, line 6

The include file '"/includes/top.inc\"' was not found.

Notice the second escape character was written when it shouldn't have been. At least I didn't think so. So then I tried this:



<script type="text/javascript" language="javascript">
if ("http://mysite2.htm"!=top.location){
document.write('<!--#include virtual="/includes/top.inc"-->')
}
</script>


Notice I used single quotes instead of double for the string and used the double quotes as the nested quotes. The error I received was "Unterminated string constant."

Then I thought that maybe the
"<!---->" may have been the cause, so I replaced the "<" and ">" with "&lt;" and "&gt;" like so:



<script type="text/javascript" language="javascript">
if ("http://mysite2.htm"!=top.location){
document.write('&lt;!--#include virtual="/includes/top.inc"--&gt;')
}
</script>


All that happened is that the include was written to the screen as text and not as an include.

I tried using the eval() function but I don't think I was using it right.

I apologize if my code is vague, but I can't paste the real code due to my company's security restrictions so I'm hoping I've provided enough information.

I'm probably missing something really simple here, but I've got no idea what else I can do. Any ideas?

glenngv
Jun 27th, 2007, 09:49 PM
http://www.codingforums.com/showthread.php?t=116773

Solution:
http://www.aspin.com/home/tutorial/scriptin/serversi