Targeting embedded div...

Discussion in 'JavaScript' started by nonicholas, Jan 15, 2009.

  1. #1
    Hello, here is my problem:

    I have a navigation bar that I have embedded on my pages (to save update time):

    < embed width="100%" height="200px" src="header.html"></embed>

    In the header I have my links, which I have assigned ids:

    < a href="index.html" class="top" id="home">Home</a>

    Then I have this javascript:

    function changeCssClass(objDivID)
    {
    if(document.getElementById(objDivID).className=='topOn')
    {
    document.getElementById(objDivID).className = 'top';
    }
    else
    {
    document.getElementById(objDivID).className = 'topOn';
    }}

    Which works perfectly with this on index.html:

    < body onload="changeCssClass('home')">

    Creating the affect that, on the home page, you know you are on the home page because "home" has a different class style. Now when I said it works perfectly, I lied. It works perfectly when the header is not embedded. My question is, how can I get the javascript to target the embedded div ids? Or is there another way to approach this?
     
    nonicholas, Jan 15, 2009 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    In all my years of web development, I have never heard of anybody <embed 'ing an html file. If your files are php, just use <?php include 'header.html'; ?>

    If they arn't php, I suggest you do some research on it, It might be time to update the site :p
     
    crath, Jan 15, 2009 IP
  3. yoavmatchulsky

    yoavmatchulsky Member

    Messages:
    57
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #3
    most web server has a server-side solution for including files (without using PHP or some sort of server-side language).

    example - if you're running Apache, you can use the mod_include module and write:
    <!--#include file="header.html" -->

    http://httpd.apache.org/docs/1.3/howto/ssi.html
     
    yoavmatchulsky, Jan 16, 2009 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    if this works, it deserves some rep for groundbreaking forward thinking!

    /me goes to embed random objects and elements in an attempt to break IE
     
    dimitar christoff, Jan 16, 2009 IP