Jump to content

Linking HTML/XHTML documetns


AndrewAK

Recommended Posts

I have a piece of JavaScript that uses some <a> elements to create navigational links on the site that I’m working with. The navigational links are on all of the pages. That makes it tedious to update or add any links. I’m wondering if there are ways that I can incorporate an .html file with a <link> element just as if I were linking a .js or .css document to an HTML/XHTML page.This is a basic <ul> that references ids from some <div>s The ids are in bold face:

<ul>	<!--1st anchor link and menu -->	<li><a href="newindex.html">Home</a> | </li>   	<!--2nd anchor link and menu --> 	<li><a href="contacts.html">Contact Us</a> | </li>        <li><a href="http://www.hogalaska.com/AdvancedGuestBook/">Guestbook</a> | </li>          <li><a href="" onclick="return clickreturnvalue()"    	onmouseover="dropdownmenu(this, event, [b]'anylinkmenu3'[/b])">Site Map</a> | </li>        <li class="navigation"><a href="" onclick="return clickreturnvalue()"    	onmouseover="dropdownmenu(this, event, [b]'anylinkmenu4'[/b])">Links</a> | </li>        <li><a href="" onclick="return clickreturnvalue()"    	onmouseover="dropdownmenu(this, event, [b]'anylinkmenu5'[/b])">Policies</a> | </li>   </ul>

The repetative code that I want to put into an external file and link to the main page:

<div id="anylinkmenu3" class="anylinkcss" style="width: 125px;">			<a href="help.html">Help</a>          	<a href="history.html">History</a>            <a href="membership.html">Membership</a>			<a href="membersonly.html">Member's Only</a>			<a href="loh.html">Ladys of Harley</a>            <a href="http://www.hogalaska.com/calendar/">Event Calandar</a></div><div id="anylinkmenu4" class="anylinkcss" style="width: 125px;">			<a href="http://www.harleyalaska.com/">Sponsor</a>            <a href="http://www.akrider.com/">Alaska Rider Tours & Rental</a>            <a href="http://www.harley-davidson.com/wcm/Content/Pages/home.jsp?locale=en_US">H.D. Motor Co.</a>            <a href="http://www.harley-davidson.com/wcm/Content/Pages/HOG/HOG.jsp?locale=en_us">H.O.G.(National)</a></div><div id="anylinkmenu5" class="anylinkcss" style="width: 125px;">			<a href="patching.html">Patching</a>            <a href="privacy.html">Privacy</a>            </div>       

FYI: This website that I'm working with is XHTML 1.0 compliant, for the most part.

Link to comment
Share on other sites

I have a piece of JavaScript that uses some <a> elements to create navigational links on the site that I’m working with. The navigational links are on all of the pages. That makes it tedious to update or add any links. I’m wondering if there are ways that I can incorporate an .html file with a <link> element just as if I were linking a .js or .css document to an HTML/XHTML page. [...]
No, an html doc can't "include" other html docs. However, the same effect is often achieved using server-side scripting (php, asp etc): you then cease to store your complete html page as a static source file, and instead store a php/asp page. When that page is requested, the script within it executes to emit the html, and since the script can include common sections etc, you could define the links once and have each page include them.If server-side scripting is not an option for you, then you can probably do it in javascript, by pulling in the same bit of javascript to each html page, and having that javascript update the html document to add your links. This has the disadvantage that it will only work when the user has enabled javascript in the browser.And there are probably other ways, too... CSS, anyone?!!
Link to comment
Share on other sites

If your webserver supports PHP I would recommend looking into some PHP, particularly the include() function. You would have to spend very much time on learning PHP, maybe an hour, and it would be a big help for maintaining your site.

Link to comment
Share on other sites

PHP again from me, in the beginning just some use of include (or perhaps include_once depending on whether it should be possible to include multiple times), and later if you do decide to learn a lot of PHP you might find that a full (preferably caching) templating system (such as smarty) would be even more apt.HTML itself does allow for things like (i)frames, but those have bad SEO implications, and so the PHP alternative is generally a much better option and has greater flexibility for later developments.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...