Computing.Net > Forums > Web Development > Redundant Information

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Redundant Information

Reply to Message Icon

Name: LANkrypt0
Date: August 5, 2005 at 16:33:35 Pacific
OS: WinXP
CPU/Ram: n/a
Comment:

I was wondering if there was a way with Javascript to replicate redundant data across web pages.

For example I have a side links bar that will be the same on every single page. Is there way to create a text file perhaps with the HTML in it and "import" that file to each page as it is loaded (sort of the way you @import a .css file)? That way I do not have to copy/paste the information on each page and it would be changeable from only one place and not have to go page by page?



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: August 5, 2005 at 19:43:29 Pacific
Reply:

Yes, you can do it, but that is what Server Side Include files are for! Of course, the hosting server must be configured to support them. Check with your ISP on that.

If you must go the JavaScript router, there will be issues if anyone has JavaScript disabled and possible cross browser compatibility issues. But, to keep it simple, just put the following code where you want the code for your menu:

<script language="javascript" src="jsmenu.js">

Of course the filename can be whatever you want it to be, just remember to include the relative path if it is in a different directory. Then in your jsmenu.js file either have a bunch of document.write's or (my preference) build a variable then do a single document.write, such as:

menuStr = 'This is the start of the menu[br]';
menuStr = 'This is the middle of the menu[br]';
menuStr = 'This is the end of the menu[br]';
document.write(menuStr);

(The less than/greater than signs around the break tags were changed to brackets for this example)


0

Response Number 2
Name: LANkrypt0
Date: August 5, 2005 at 20:15:53 Pacific
Reply:

Awesome, that worked! While the file is big, it's a lot better than having all that redundant information in HTML files. Quick question though. In the document writes, does a / need to be proceeded by a \.
For example:
[a href="test.html"]Click[\/a]
or could I:
[a href="test.html"]Click[/a]

(The less than/greater than signs around the break tags were changed to brackets for this example)



0

Response Number 3
Name: Michael J (by mjdamato)
Date: August 5, 2005 at 20:49:41 Pacific
Reply:

I know there's a reason to use \/ instead of just /, but I'm not sure when that applies.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Redundant Information

HTML form not saving information www.computing.net/answers/webdevel/html-form-not-saving-information/707.html

I need apache information www.computing.net/answers/webdevel/i-need-apache-information/2425.html

PHP - saving a file www.computing.net/answers/webdevel/php-saving-a-file/2142.html