SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict miggl's Avatar
    Join Date
    Feb 2007
    Location
    Los Angeles, CA
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic object doesn't register.

    Hey folks!

    Here's another tough one: I have an object (ActiveX / FF Extension) tag that I add dynamically via JavaScript after the page has loaded by calling the creating function in the body.onload event.

    It works if I do not dynamically create the object, meaning coding it inline in the HTML code. However, as I want to manipulate it at run-time (depending on browser capabilities and such) I really need to load it after the rest of the page has already loaded. Now the problem is that it won't register the object.

    This works:
    Code:
    <html>
    <head>[...]</head>
    <body>
    <object id="blabla" class="clis:blabla" codebase="blabla"></object>
    </body>
    </html>
    This does not work:
    Code:
    <html>
    <head>
    <script type="text/javascript" src="blabla.js"></script>
    </head>
    <body onload="init();">
    </body>
    </html>
    
    *********************************
    blabla.js:
    *********************************
    function init()
    {
    var o_object = document.createElement("object");
    
    o_object.id = "blabla";
    o_object.setAttribute("classid", "blabla");
    o_object.setAttribute("codebase", "blabla");
    document.body.appendChild(o_object);
    }
    Any ideas how I can work around this? This is really killing me!

    Thanks!
    Celebrate Liberty, Freedom, and Rights at The Constitutionalist.

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,343
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    You are creating the element but not associating it to the body (as a child node of body).
    Not sure that is your (only) problem, but worth a look.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Addict miggl's Avatar
    Join Date
    Feb 2007
    Location
    Los Angeles, CA
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    document.body.appendChild(o_object);
    That should attach it.
    Celebrate Liberty, Freedom, and Rights at The Constitutionalist.


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
  •