SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change embed src using javascript

    I'm trying to change embed src using document.getElementById.
    what am i missing?

    HTML Code:
    <script language="JavaScript" type="text/JavaScript">
    
    myDate = new Date();
    myTD = myDate.getTimezoneOffset();
    alert(myTD);
    if ((myTD >= 180) && (myTD < 480)){
    document.getElementById('localswf').setAttribute('src','one.swf');
    }else if((myTD >=180) && (myTD < 180)){
    document.getElementById('localswf').setAttribute('src','two.swf');
    }else if((myTD >= -540) && (myTD < -180)){
    document.getElementById('localswf').setAttribute('src','three.swf');
    
    }else{
    document.getElementById('localswf').setAttribute('src','four.swf');
    }
    
    </script>
    
    
    
    </head>
    <body>
    <div> 
      <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="105" height="105  ">
        <EMBED src='one.swf' name="localswf" id="localswf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="105" height="105"></EMBED></OBJECT>
    </div>
    
    </body>

    thanx

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put this in variable somewhere on top:
    Code JavaScript:
    var objLoc = document.getElementById('localswf');
    and then replace all lines like
    Code JavaScript:
    document.getElementById('localswf').setAttribute('src','one.swf');
    with
    Code JavaScript:
    objLoc.src = 'one.swf';
    objLoc.src = 'two.swf';
    ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •