Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 04-21-2009, 02:08 PM   #1 (permalink)
 
Newb Techie

Join Date: Apr 2009

Location: Oklahoma City, OK

Posts: 2

livingstons_auction is on a distinguished road

Default html from src file

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.

Last edited by livingstons_auction; 04-21-2009 at 02:19 PM.
livingstons_auction is offline  
Old 04-21-2009, 05:02 PM   #2 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default Re: html from src file

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>
<link rel="stylesheet" href="js_styles.css"
type="text/css" />

<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>
<script type="text/javascript" src="travel.js">
/*<![CDATA[ */
/* ]]> */
</script>


</body>
</html>
*code by Eric Maddan (oldskool)
this solution was for a problem in Javascript 4th Edition by Don Gosselin

Last edited by oldskool; 04-21-2009 at 05:09 PM. Reason: added code for example
oldskool is offline  
Old 04-21-2009, 07:07 PM   #3 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: html from src file

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 Code:
<?php

include ('menu.html');

// dynamic stuff here

?>

__________________

Need website help? PM me!
CrazeD is offline  
Old 04-21-2009, 09:42 PM   #4 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default Re: html from src file

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.
oldskool is offline  
Old 04-22-2009, 11:39 AM   #5 (permalink)
 
Newb Techie

Join Date: Apr 2009

Location: Oklahoma City, OK

Posts: 2

livingstons_auction is on a distinguished road

Default Re: html from src file

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.
livingstons_auction is offline  
Old 04-22-2009, 03:46 PM   #6 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: html from src file

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.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 04-22-2009, 06:18 PM   #7 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: html from src file

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.
__________________

Need website help? PM me!
CrazeD is offline  
Old 04-25-2009, 02:41 PM   #8 (permalink)
SapperX's Avatar
 
Putting the X in Sapper

Join Date: Jul 2007

Location: USA

Posts: 706

SapperX is on a distinguished road

Default Re: html from src file

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.
__________________
My Current PC-
eVGA 680i | Intel Q6600 G0 |Western Digital 250gb HD
Seagate 500gb HD | Western Digital 500gb HD | VisionTek HD4870 | 4gb Cruical Ballistix Tracer DDR2 800
600w Coolmax Silent Fan PSU | Cooler Master Centurian 590 | Samsung 24" LCD | Dell 22" LCD

-900HA EEE pc
SapperX is offline  
Old 04-26-2009, 09:50 AM   #9 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: html from src file

Quote:
Originally Posted by SapperX View Post
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.
__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

Tags
embed, file, html, link, source

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
My Dell computer is infected tamdiaz HijackThis Logs (finished) 13 04-01-2009 11:14 PM
Installing Ubuntu. 95BlackGA Linux, BSD, other *nixes & Open Source Software 1 10-16-2008 09:44 PM
A sneaky, and annoying virus donaldj HijackThis Logs (finished) 25 06-16-2008 08:58 PM
WTF is a Bad Block? MikesCreation Hardware Troubleshooting 18 02-24-2008 09:31 PM
Another Hijack Log boo HijackThis Logs (finished) 17 06-26-2007 12:30 PM