Click to See Complete Forum and Search --> : SSI Effect using Javascript?
livealot
12-28-2002, 03:11 AM
Hi
I've got a text file which I want to put on all of my pages, so that I can update the file and it'll update all of the pages. Normally I'll use SSI to do this, but I don't have that option in this case. I've seen the code to do this using Javascript before but I can't remember it. Can someone please post the code?
Thanks
blufive
12-28-2002, 05:09 AM
Well, the obvious way is to use an external javascript which just document.write()s the common text into the page.
Charles
12-28-2002, 05:42 AM
Originally posted by blufive
Well, the obvious way is to use an external javascript which just document.write()s the common text into the page. Considering that more than ten percent of users do not use JavaScript, you would need to also have an HTML version of the "included" material. And you would need to use the NOSCRIPT element to provide a link to this HTML version for the JavaScript free people like me. Perhapse the better solution is the IFRAME element. You will still need to provide a link for the good IFRAME free folk, but you only need one version of the "included" material.
<iframe src="http://www.w3.org/TR/html4/present/frames.html#edef-IFRAME"><a href="http://www.w3.org/TR/html4/present/frames.html#edef-IFRAME">http://www.w3.org/TR/html4/present/frames.html#edef-IFRAME</a></iframe>
livealot
12-28-2002, 02:02 PM
Originally posted by blufive
Well, the obvious way is to use an external javascript which just document.write()s the common text into the page.
I don't know that much about Javascript could you please give me the code so that I can do that?
livealot
12-28-2002, 02:24 PM
Originally posted by Dave Clark
JavaScript cannot read files, so this text would have to be completed converted to JavaScript code. Meaning, you would have to maintain your "text" in a completely JavaScript format -- very time consuming. The second post, above, alludes to this.
If the third post, above, is also not to your liking, I know of an IE-only HTML method for getting the content of a normal text file loaded into a JavaScript string variable. The resulting content of this JavaScript variable could then be easily written out as HTML using a single JavaScript statement.
Are you interested in this IE-only solution?
Dave
Yes, I would be interested. Does it just show up as nothing on Netscape?
Charles
12-28-2002, 02:41 PM
It will also show up in any instance of Internet Explorer that had scripting turned off. That's at least one in ten times that it will fail.
blufive
12-28-2002, 03:07 PM
I was referring to stuff like this:(in your html files)
<script type="text/javascript" src="include.js"></script>
(include.js)
document.write("<h1>I'm a header to be included</h1>")
document.write("I'm a line of text to be included<br>") There's an example of this in use at the demon.co.uk site in my .sig.
As pointed out above, this stuff is useless if javascript is turned off or otherwise unavailable, but then so is any other method using JS.
I suspect your objective is to keep a single version of the document, in which case you have a choice: use the method I've outlined here, and screw things up for the javascript-impaired use iframes, as mentioned by Charles. IIRC, iframe support can be ropy in older browsers, and it may not give the visual effect you want.
use the IE-only javascript options outlined by Dave, and screw things up for those without javascript or using browsers other than IENone of these is ideal, but the best solution is SSI, which you explicitly ruled out in your question.
blufive-
Instead of using multiple document.write commands, you'd be better off using this format.
document.write ('<h1>I'm a header to be included</h1>',
'Here is a line of text to be included<br>',
'Here is another line of text to be included');
Originally posted by blufive
None of these is ideal, but the best solution is SSI, which you explicitly ruled out in your question.
PHP would be a good way to do this as well...Is this an option, livealot?
<?php
include("test.htm");
?>
or
<?php
require("test.htm");
?>
blufive
12-28-2002, 05:21 PM
Instead of using multiple document.write commands, you'd be better off using this format. I'll leave that decision to the individual writing the code in question.
PHP would be a good way to do this as well...Is this an option, livealot? PHP is server-side, too, so I'd count it as a server-side include. That said, if it's available, go for it.
(Regarding javascript)
thecounter.com reports approx 10% of users with no javascript capability: http://www.thecounter.com/stats/2002/December/javas.php
This site: http://www.upsdell.com/BrowserNews/res_design.htm Quotes 11% without javascript, and has some sensible things to say about stats in general, over here: http://www.upsdell.com/BrowserNews/stat.htm
Given statistical error and similar caveats, both mesh well with Charles' quoted 10/12%.
Many users disable JS as a way of killing popups, status bar fiddling, and similar unpleasantness.
"But there are better ways to block popups", I hear you cry. I know that, you know that, but people still do it.
Yeah, I was guessing that PHP wouldn't be an option if SSI wasn't, but I thought I'd bring it up. :)
Charles
12-29-2002, 05:33 AM
No matter how you cut it, 10 or twelve percent, it's a huge number and because it includes people who, because of their disability, cannot use JavaScript the law has much to say about JavaScript dependent sites.
Let's take a look at those raw numbers.From http://www.thecounter.com/stats/2002/November/javas.php
Fri Nov 1 00:05:01 2002 - Sat Nov 30 23:55:05 2002 30.0 Days
Javascript 1.2+: 309600823 (88%)
Javascript <1.2: 848682 (0%)
Javascript false: 38101069 (10%)So 12% of users do not use JavaScript 1.2 or more recent. If by "JavaScript" you mean "JavaScript 1.2 or more recent" then my 12% number stands. And unless you are going to look up every object, method and property in your script to see when it was introduced, you are most likely using JavaScript 1.2 or more recent without knowing it. Document.write belongs to JavaScript 1.0, so I'm again correct in writing that relying upon it to "include" a file will fail 10% of the time.
Keep in mind that for some things the JavaScript failure is higher than 12%. Mouse over events don't happen when a user cannot use a mouse. Netscape and Opera both allow users to disable pop-ups as does Norton Internet Security.