Search billions of records on Ancestry.com
   

SEARCHES FAMILY TREES MAILING LISTS MESSAGE BOARDS

View SSI Data in your Local Folders

A JavaScript Solution

Back in June 2008, I posted a note to the Freepages Help List describing a method to display locally your Server Side Includes data.

http://archiver.rootsweb.ancestry.com/th/read/Freepages-Help/2008-06/1214599681

Since then I have received positive 'feedback' on the JavaScript method I used, along with some requests for a more detailed explanation of the 'how to' in getting it to work. The description that follows assumes you have already implemented SSI and your navigation data is saved as a .txt file to the server. Example nav file:-

<div id="nav">
<p class="nav_hdg">Navigation</p>
<a href="http://mydomain.com/elements/">Create New Elements</a><br />
<a href="http://mydomain.com/corners/">Cute Corners</a><br />
<a href="http://mydomain.com/encryptor/">Encrypt Email Address</a><br />
<a href="http://mydomain.com/filezilla/">FileZilla FTP</a><br />
<a href="http://mydomain.com/ieftp/">Internet Explorer FTP</a><br />
</div><!--end #nav-->

The above navigation is using 'absolute links' and there lies the first problem. Any local navigation using those links will point at the urls concerned and not the local file which you may have been working with. This is where using JavaScript for your local navigation will have its greatest benefit - though you need to remember when changing the SSI .txt file to remake the equivalent .js file using the relative links.
TIP!!.. This duplication can be avoided if you use 'relative' navigation throughout your site - keeping your local web folders matching the server directories.

We now have a relative link file as follows:-

<div id="nav"><!-- local nav -->
<p class="nav_hdg">Navigation</p>
<a href="../elements/new_element.html">Create New Elements</a><br />
<a href="../corners/corners.html.html">Cute Corners</a><br />
<a href="../encryptor/encryptor.html">Encrypt Email Address</a><br />
<a href="../filezilla/filezilla.html">FileZilla FTP</a><br />
<a href="../ieftp/ieftp.html">Internet Explorer FTP</a><br />
</div><!--end #nav-->

Note that the navigation is all up one level, then to a new directory and file name. Locally I use separate names to avoid confusion when having more than one 'index' file sitting in the tabs of the text editor at the same time. The file name is changed to index.html after it has been placed on the server.

Its now time to convert the HTML data into JavaScript. This entails 'escaping' forward slashes '/' by preceding them with a back slash '\' and writing one line at a time. Thankfully we have an online converter available do this for us, so go to - http://tinyurl.com/2m9p3s

1.. Uncheck the "Include <script> tags" box.
2.. Copy & Paste your Local Nav file into the text box.
3.. Click "Convert to JavaScript" and you will now have:-

function writeJS(){
var str='';
str+='<div id="nav"><!-- local nav --> ';
str+='<p class="nav_hdg">Navigation<\/p>';
str+='<a href="..\/elements\/new_element.html">Create New Elements<\/a><br \/>';
str+='<a href="..\/corners\/corners.html.html">Cute Corners<\/a><br \/>';
str+='<a href="..\/encryptor\/encryptor.html">Encrypt Email Address<\/a><br \/>';
str+='<a href="..\/filezilla\/filezilla.html">FileZilla FTP<\/a><br \/>';
str+='<a href="..\/ieftp\/ieftp.html">Internet Explorer FTP<\/a><br \/>';
str+='<\/div><!--end #nav-->';
document.write(str);
}
writeJS();

4.. Click in the text box then Ctrl +A (to highlight all the text), then Ctrl +C
5.. Open a page in Notepad (or your text editor) and Ctrl +V to paste the contents.

Now save the contents using the same name as your SSI .txt file but with the .js extension.

You should now add to all your pages where you have the SSI #include file the script tags and source of the new .js file. This should look similar to the following:-

<!--#include virtual="../objects/fixed_nav.txt" -->
<script type="text/javascript" src="../objects/fixed_nav_local.js"></script>

Remember!!! The JavaScript file is not loaded to the server, else you will finish up with two helpings of your menu.

Also, when viewing the source code of a page from your local folders in which the SSI information is showing, you will see both the #include and JavaScript code lines shown in the previous paragraph. When viewing the server file, the #include will be replaced with the actual HTML and the JavaScript doesn't run.


ssi-copyright