🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: best.general
Article #335

Re: Javascript, SSI's, cookies

#335
From: Joe Smith
Date: Sat, 13 Oct 2001 20:14
68 lines
3471 bytes
In article <9q6gho$28qo$1@nntp1.ba.best.com>,
Malcolm Hoar <malch@malch.com> wrote:
>In article <9q5goq$2413$1@nntp1.ba.best.com>, inwap@best.com (Joe Smith) wrote:
>>>Is there a way to use javascript or an SSI to read a [session] cookie,
>>>then include a header file depending on the presence or absence or value
>>>of that cookie?  (rather than using a cgi script)
>>
>>SSI (Server Side Includes) have to be done on the server, NOT on
>>the browser.
>
>Et tu Joe.
>
>That was my first reaction too.
>
>>>javascript snippet
>>>---------------------
>>>var foo = getCookie('foo');
>>>getCookie('foo');
>>>if (foo == 'red') {
>>> document.write('<!--#include
>>>file="/webadmin/home/pub/login/public_html/test.html" -->');
>>
>>That tells JavaScript running on the browser to put an angle bracket,
>>exclamation point, two hyphens, a pound sign and other stuff in 
>>the browser's cache.  The BESTWWWD never sees that string.
>>SSIs have to exist in the *.shtml file on the server in order for
>>the server to do anything with it.
>
>But the server can expand the SSI *before* the document
>(including the JS) is sent to the client.

D'oh!

That's right.  The browser does not see the #include because server has
modified the Javascript *before* it gets sent out.

>I think that SSI tags do often need to be on one line. So
>it may be better to write this as:
>
>document.write('
><!--#include file="/webadmin/home/pub/login/public_html/test.html" -->
>');
>
>However, I don't know enough about JS to be sure how multi-line
>quoted string literals are handled. That may demand a tweak.

If I remember correctly, embedded newlines must be backslashed.

That would explain what the original poster reported.  A line like
  document.write('<!--#include file="test.html"-->')
would get translated to
  document.write('This is the contents of test.html')
if the file consisted of one line of text (without the trailing newline).

One thing to try is to put a backslash at the end of every line in the
included file, and make sure there are no embedded apostrophes.  Then
  document.write('<!--#include file="test.html"-->')
would get translated to
  document.write('This is the contents of test.html, a file\
that has three lines.\
Each line of the file ends with a backslash.\
')

Then use the browser's "View Source" feature to make sure that the correct
text has been sent to the browser.
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
Technical Details
Message-ID: <9qa7ab$2li0$1@nntp1.ba.best.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news1.best.com!nntp1.ba.best.com!inwap
References: <3BC60DBD.19B3E030@superkids.com> <9q5goq$2413$1@nntp1.ba.best.com> <9q6gho$28qo$1@nntp1.ba.best.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f9f6d,e3a236c74c55f283
X-Google-Attributes: gidf9f6d,public
X-Google-ArrivalTime: 2001-10-13 13:14:07 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news1.best.com!nntp1.ba.best.com!inwap
From: inwap@best.com (Joe Smith)
Newsgroups: best.general
Subject: Re: Javascript, SSI's, cookies
Date: Sat, 13 Oct 2001 20:14:03 +0000 (UTC)
Organization: Chez Inwap
Lines: 68
Distribution: best
Message-ID: <9qa7ab$2li0$1@nntp1.ba.best.com>
References: <3BC60DBD.19B3E030@superkids.com> <9q5goq$2413$1@nntp1.ba.best.com> <9q6gho$28qo$1@nntp1.ba.best.com>
NNTP-Posting-Host: shell3.ba.best.com
X-Trace: nntp1.ba.best.com 1003004043 87616 206.184.139.134 (13 Oct 2001 20:14:03 GMT)
X-Complaints-To: abuse@best.com
NNTP-Posting-Date: Sat, 13 Oct 2001 20:14:03 +0000 (UTC)