Forum Moderators: open

Message Too Old, No Replies

Reference a <div> like js

         

llmm123

7:00 am on Apr 4, 2007 (gmt 0)

10+ Year Member



Hi all,

Another newbie question from my side...

I have a div that looks like:


<div id="mydiv" class="myclass">
.
.
.
whole lot of code/text
.
.
.
</div>

This div is displayed on almost all my pages. Can I move it out to a seperate folder and just reference it in each page, like I do with jscripts or stylesheets I.E


<link href="mystylesheet.css" rel="stylesheet" type="text/css">

or

<script src="js_myjs.js" type="text/javascript"></script>

Thanks,
LL

bill

8:40 am on Apr 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're looking for server side includes [google.com]. We've had a few threads on that topic. ;)

ahmedtheking

1:39 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah SSI would do the job, but you could also do it with JS, but it would be long! You can have the div their in every page, but using a JS file, that you'd link, you can figure out what page the user's on and whether the div needs to be displayed. You can then, using AJAX, 'dynamically' assign data to that div.

Fotiman

2:41 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As bill pointed out, you should use server side includes for this.

You should NOT use JavaScript for this. Why? Because you'd be adding a JavaScript dependency to deliver content, which will make your content not accessible to everyone. Use JavaScript to "enhance" your content and provide behaviors, but don't use it the only means to deliver content.

g1smd

7:10 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I use PHP includes for just this very purpose. Repetitive content is filed just once and then included where necessary.

It takes slightly longer to set up this way, but makes the site updating very much more efficient in the future.