html from src file

Status
Not open for further replies.

livingstons_auction

Beta member
Messages
2
Location
Oklahoma City, OK
How can I use HTML code from a file?

Example: When using javascript you can write the code in a .js file then link to that file using this line of code:
Code:
<script type="text/javascript" src="somejavascript.js"></script>

I want to do know how to do the same thing with HTML. This should help make it easier to maintain the menu bars in my static sites.

I may not have worded my question properly. (Possibly why I couldn't find what I need from google.) But, I hope that what I'm trying to ask is still clear.
 
Put this in the <HEAD> section of the HTML file:

Code:
<link rel="stylesheet" href="js_styles.css"
type="text/css" />

You obviously would have - in this case - a "js_styles.css" file in the same directory as the HTML file, otherwise you would have to "point" to it. And a .js file as well.

Also, there is a .js reference down at the bottom of the code, for the .js file...

EDIT: Here is an example.... Try that out if you like.

Code:
<html>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<head>
[B]<link rel="stylesheet" href="js_styles.css"
type="text/css" />[/B]

<script type="text/javascript">
document.write("<h1>Don's Jungle Tours</h1>")
/* <![CDATA[ */
//Code written by: Eric Maddan
//Date:1-21-09
//Case Project 1-4
/* ]]> */
</script>
</head>

<body>

<h2>Adventure</h2>
<script type="text/javascript">
/* <![CDATA[ */
document.write("<ul>");
document.write("<li>Ecotourism is our specialty</li>");
document.write("<li>Get up close and personal with nature</li>");
document.write("<li>Destinations include Africa, South America, and Asia</li>");
document.write("</ul>");
/* ]]> */
</script>

<h2>Excellence</h2>
[B]<script type="text/javascript" src="travel.js">[/B]
/*<![CDATA[ */
/* ]]> */
</script>


</body>
</html>

*code by Eric Maddan (oldskool)
this solution was for a problem in Javascript 4th Edition by Don Gosselin
 
What you're asking can't be done by reasonable means. You could use frames or iframes, but that's ugly and is no longer recognized as an acceptable solution.

What oldskool mentioned above is for CSS stylesheets, but they can't contain HTML.

In order to do what you want, you would need a serverside language that supports including other files, such as PHP.

PHP:
<?php

include ('menu.html');

// dynamic stuff here

?>
 
Ok, I see what the OP is asking now, I just thought he wanted an example of how to refer to a .js file from within HTML code.
 
Thanks CrazeD and OldSchool. Too bad what I was hoping to do cant be done, reasonably.

Can yall suggest some better ways to maintain my site's menu bars?

I am using DreamWeaver. The find/replace all function is very useful but can be troublesum at time.

Our web host does not supply a Database.
 
Your web host won't let you have any type of database? I would dump them.

Like CrazeD said you will have to use a server side scripting language such as PHP to dynamically create this content. The way to do it would be to use heredocs to create variables containing your html and then just "stitch it all together". This way changing one variable would apply the same change everywhere the variable is used.
 
You don't need a database to do what you want. But yeah, if your host doesn't allow a database then I would definitely find a better host.
 
I'm assuming from your questions that you wanted to do this in order to easily change the look of your site's navigation? In that case just use CSS and apply styles to all of them at once. If this is what you are trying to do and you don't know about CSS, stop making any kind of website, learn css, then create the same website in 1/8 the time.
 
I'm assuming from your questions that you wanted to do this in order to easily change the look of your site's navigation? In that case just use CSS and apply styles to all of them at once. If this is what you are trying to do and you don't know about CSS, stop making any kind of website, learn css, then create the same website in 1/8 the time.

I believe he is making a duplicate of an original HTML page then just changing the content on the different pages. So to change something on the nav, he'd have to edit every page. Using CSS does nothing here.
 
Status
Not open for further replies.
Back
Top Bottom