AbelCam Forum
Download AbelCam buy Pro
 
 
 
Welcome Anonymous User
11/22/2024 - 10:23 PM
Quick Search:
Quick Jump:
 
Announcements
Latest Topics
 
Combining Javascript and Server Side Includes
By: Norman
Rank: Frequent User
Topics: 28
From: San Jose, CA - USA
Added: 11/27/2006 - 02:37 AM

Is there a way to use javascript to write server side includes? "!" Has to be escaped with an "\" before it will be allowed and with a "\" the server will not count it as a include. Using %21 or &#33 doesn't seem to help either...

Example:
<script type="text/javascript">
	document.write('TEXT BEFORE <\!--#include file="/include/head.inc" --> TEXT AFTER');
</script>
Produces:
"TEXT BEFORE TEXT AFTER"
The server of course ignores the include inside of the javascript. Also in your example (from the help files):
<script type="text/javascript"><!-- 
camArray = new Array();
<!--#camarray -->
camNameArray = new Array();
<!--#camnamearray -->
//--></script>
<script type="text/javascript" src="/include/functions.js?cam=<!--#currentcam -->"></script>
Wouldn't those nested comments be incorrectly considered, like the following in bold?
<script type="text/javascript"><!-- 
camArray = new Array();
<!--#camarray -->
camNameArray = new Array();
<!--#camnamearray -->
//--></script>
<script type="text/javascript" src="/include/functions.js?cam=<!--#currentcam -->"></script>
Putting comments inside of comments seems to be another small problem I am having. It's not like placing <div>'s inside of <div>'s. They don't seem to nest well. Is it possible perhaps to tell the server you want to include something without using the standard html comment structure or is there another method I am not seeing?
"Turn off your computer and await further instructions."
By: sse
Rank: Forum Addict
Topics: 73
From: n/a
Added: 11/27/2006 - 05:49 AM

Hello Norman

As the name implies, server side includes are evaluated on the server side.
JavaScript is done in the browser on the viewers end.

You cannot use JavaScript to write server side includes, because when the browser starts to execute the JavaScript, the server side includes have been replaced already.


The 'nested comments' you found in the help file are part of every LogiSphere installation,
you'll find them in wwwroot\include\header.inc

They don't hurt, because the <!--#camarray --> and <!--#camnamearray --> will be replaced by JavaScript code before delivery to the browser.

Summary:

- server side includes are processed by LogiSphere before the file is delivered to the browser.

- JavaScript is processed in the browser when the file requested is completely loaded.
By: Norman
Rank: Frequent User
Topics: 28
From: San Jose, CA - USA
Added: 11/27/2006 - 07:28 AM

Well that makes sense when I look at it that way! Thanks!

(Doing a little thinking outloud here)

So that would mean a file named hello.inc that contained
hello
Would be OK to write up as:
<script type="text/javascript">
	document.write('<!--#include file="/include/hello.inc" -->');
</script>
because by the time it got to the browser it would be:
<script type="text/javascript">
	document.write('hello');
</script>


Yes! That works!

Thanks Stefan, I was pulling my hair out on this one... I was just thinking backwards as usual Roll Eyes