[WEB4LIB] Inserting html code using JavaScript

Thomas Dowling tdowling at ohiolink.edu
Fri May 6 09:04:19 EDT 2005


Murali N wrote:
> I need to put a navigation bar in plenty of HTML pages and requires a 
> lot of time to update navigation bar once a week. Currently, our library 
> web site hosted in remote computer as I don’t have much control on over 
> it. Could someone help me to insert html code from an external file 
> using JavaScript in place of SSI (Server side includes)?
> 


A couple of suggestions (descending order of preference IMHO).

First, come up with a navigational bar that doesn't change.  I don't
know what you're doing that requires the nav bar to change every week,
but that's typically a place for very persistent URLs.  Whatever is
changing that requires you to rewrite your nav bar is also breaking any
links or bookmarks your users have into your system.  I added one item
to our nav bar a few months ago, but otherwise it has been unchanged for
several years.

Second, if the root of the problem is inadequate access to your own
pages, address that.  SSI is [one of the] right tool[s] for the job; get
 a hosting solution that allows it.

Third, look for a global search/replace function on your server.

Fourth, author your site with an HTML editor that has a templating
function.  Change the nav bar template as needed and
regenerate/re-upload your HTML.

Fourth, you might try something like this:

  <head>
  <script type="text/javascript"
    src="/file-that-contains-navBar.js"></script>
  </head>
  <body>
  <script type="text/javascript">navBar()</script>
  <noscript><!-- static, no-JS nav bar here --></noscript>
  </body>

Edit file-that-contains-navBar.js as needed.


-- 
Thomas Dowling




More information about the Web4lib mailing list