Forum Moderators: open

Message Too Old, No Replies

how do you use javascript to...

load the contents of an html file into a table cell

         

bubba4gman

3:48 am on Jun 24, 2005 (gmt 0)

10+ Year Member



I need to load an html file, which would contain a logo and navigation bar, into a table cell. Point being, I have 7 pages that all have the logo and nav bar at the top and I want to be able to make nav bar changes in one html file, rather than having to change all 7 pages. I'm doing it now with an IFrame, but would prefer to do it with javscript so I can have full screen scrolling capability.

Thanks!

rocknbil

5:35 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't believe you can, SSI or some other server-side inclusion is a better solution.

Alternatively you can do an entire document write on the navigation, put this code in a singgle .js file, and include the JS in every page - but that is a Very Bad Idea (burying links in Javascript.)

Nutter

10:04 pm on Jun 25, 2005 (gmt 0)

10+ Year Member



You could probably do some sort of XMLHTTPRequest.

But, server side would be a better choice.

bubba4gman

12:25 am on Jun 26, 2005 (gmt 0)

10+ Year Member



not sure what you mean by server side. The html would be server side. I want to create the logo and nav bar, upload the file to my server, and have each page reference that file to display the logo and nav bar. I'm looking for an alternative to using a IFrame, so that the nav bar will be part of the page and scroll with the page. I could just put it in the html of page, but I was looking to do something that would make it quick and easy to update in the future.

ControlEngineer

1:48 am on Jun 26, 2005 (gmt 0)

10+ Year Member



bubba4gman:
not sure what you mean by server side.

As I understand it, server side includes (SSI) require that the server (for most of us, our ISP or educational institution's computer) have the software to insert a file stored on the server into our web page before it is delivered to the viewer's browser.

If your server supports it, for most purposes it is the best solution. However, if your web site is hosted on a server (or your plan does not include it) SSI is not available.

A situation I have recently worked with is a large number of web sites built by local groups, mostly campus organizations. Many are hosted on university systems (university IT departments can be very picky about students and professors using server side anything), free (Geocities, etc.) hosting, and sometimes full featured hosts. A national organization would like the local web sites to display some text from the national organization that changes frequently. We have used IFRAMEs with success. Another method is javascript that references a remote script containing document.write methods.

I notice that both methods are used for affiliate programs and news feeds (that don't use RSS). Both the affiliates and news feeds include links.

Nutter

2:30 am on Jun 26, 2005 (gmt 0)

10+ Year Member



Server side - ASP, PHP, etc as opposed to javascript which (typically) runs on the client computer. If your host supports PHP it's a simple call to include(). I'm sure SSI and ASP have similar commands, I'm just not as familiar with them.

kaled

9:12 am on Jun 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I understand it, server side includes (SSI) require that the server (for most of us, our ISP or educational institution's computer) have the software to insert a file stored on the server into our web page before it is delivered to the viewer's browser.

SSI works independantly of ISPs etc. In this case "server" refers to the computer on which the website is stored.

It's pathetic that client-side (browser) includes are supported for javascript anf for images but not for text/html. However, that is the reality of the situation.

Using javascript to implement essential functionality is to be avoided where possible. In this case, IFrames or SSI is the solution for static html. For dynamic pages (php, etc.) the problem is largely academic.

Kaled.

rocknbil

5:43 pm on Jun 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



not sure what you mean by server side. The html would be server side.

When the html page hits the browser, it is now client-side, which is the environment in which Javascript works.

Anything that occurs at the server before the page is delivered is considered a server-side action. This includes dynamic output from scripts or SSI.

So, create a file that contains any redundant data, such as your navigation section. Name it whatever you want (mynav.txt.)

Rename an HTML file with an .shtml extension. This tells the server to parse the page looking for server-side include (SSI) commands.

In that page, replace your navigation with

<!--#include file="mynav.txt" -->

If mynav.txt is in some other directory, you need to use virtual:

<!--#include virtual="directoryname/mynav.txt" -->

The space after the last quote (" -->) is important.

Upload it to the server and request the page (don't forget .shtml, not .html.) If you see nothing at all, server-side includes are not enabled; contact your administrator. If you see "an error occurred while processing this directive" you've done something wrong, Google for SSI docs and tutorials.

ControlEngineer

6:27 pm on Jun 26, 2005 (gmt 0)

10+ Year Member



SSI works independantly of ISPs etc. In this case "server" refers to the computer on which the website is stored.

True. However, for many small, non-profit sites the host is their ISP, or some other cheap service. For example, if Joe's Internet Serive, an ISP, also hosts the site (often as a part of the ISP service package) the server is Joe's computer. Whether or not SSI will work depends upon Joe. The larger problem are organizations whose site is hosted on an educational or other institutional server.

It's pathetic that client-side (browser) includes are supported for javascript anf for images but not for text/html. However, that is the reality of the situation.

Very true. In simple html we can source an image from other sites. It seems like we should just easily pull in a file of text (with html tags). When I get appointed ruler of the world that will be on my list of things to change. Of course, that list is already too long :-}

Using javascript to implement essential functionality is to be avoided where possible. In this case, IFrames or SSI is the solution for static html. For dynamic pages (php, etc.) the problem is largely academic.

I always feel doubtful about using javascript for essential functions. However, I have never had any problems clicking on links to JS based news feeds. (not yet,at least).

SSI on a server that can handle it is my preference. I also like php, when available.

I am not familiar with risks that may be involved with IFrames, although I have seen them used and they have worked for me. I don't know about support on older browsers, however.