Waiting for ActiveX object to have initialized

Discussion in 'Javascript' started by marcosnogood@lycos.com, May 1, 2006.

  1. Guest

    Hello,

    I need to dynamically load an activex object because what
    object to load is based on certain conditions. Also I need to
    wait for the object to have initialized before moving on. What I did
    was having the activex object set a variable and have the javascript
    spin on that variable (a wait function)...

    function load() {
    var newsection = document.createElement('div');
    var newcode = '<object codebase = ' + what_to_load() + '....><script
    javascript....>' +
    ' wait_on_new_activex_object_prop()</script>';
    newsection.innerHTML = newcode;
    ....
    }

    Note that I did not want to overwrite the entire page by using
    document.write(), that is why I created a new element to
    load the activex object...

    However this code does not work, the wait javascript function
    wasn't executed at all (I tried to put an "alert()" there, it didnt
    get called either)... it looks like IE cannot execute dynamically
    created javascript.

    Is there another way to accomplish what I am trying to do? Any
    idea would be really helpful.

    Thanks.
     
    , May 1, 2006
    #1
    1. Advertising

  2. Randy Webb Guest

    said the following on 5/1/2006 4:32 AM:
    > Hello,
    >
    > I need to dynamically load an activex object because what
    > object to load is based on certain conditions. Also I need to
    > wait for the object to have initialized before moving on. What I did
    > was having the activex object set a variable and have the javascript
    > spin on that variable (a wait function)...
    >
    > function load() {
    > var newsection = document.createElement('div');
    > var newcode = '<object codebase = ' + what_to_load() + '....><script
    > javascript....>' +
    > ' wait_on_new_activex_object_prop()</script>';
    > newsection.innerHTML = newcode;


    Why are you using createElement and then trying to innerHTML something
    into it? And, you aren't appending your newsection unless you left that
    code out.

    > ....
    > }
    >
    > Note that I did not want to overwrite the entire page by using
    > document.write(), that is why I created a new element to
    > load the activex object...


    You can do a document.write there if it is done while the page is loading.

    > However this code does not work, the wait javascript function
    > wasn't executed at all (I tried to put an "alert()" there, it didnt
    > get called either)... it looks like IE cannot execute dynamically
    > created javascript.


    Sure it can. Just not the way you are trying to dynamically create it.

    > Is there another way to accomplish what I am trying to do? Any
    > idea would be really helpful.


    Use createElement to create a script element, create its .text property
    and off you go.

    var newScript = document.createElement('script');
    newScript.text = 'alert("This is the alert")';
    document.getElementById('someContainer').appendChild(newScript);

    But, why not use createElement to create the OBJECT tag as well?

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, May 1, 2006
    #2
    1. Advertising

  3. VK Guest

    wrote:
    > Hello,
    >
    > I need to dynamically load an activex object because what
    > object to load is based on certain conditions. Also I need to
    > wait for the object to have initialized before moving on. What I did
    > was having the activex object set a variable and have the javascript
    > spin on that variable (a wait function)...
    >
    > function load() {
    > var newsection = document.createElement('div');
    > var newcode = '<object codebase = ' + what_to_load() + '....><script
    > javascript....>' +
    > ' wait_on_new_activex_object_prop()</script>';
    > newsection.innerHTML = newcode;
    > ....
    > }


    Nice try, but you are late for few years. This trick was explored in
    deep in 90's (with devastating results for IE users). Now at least this
    hole (use <object> as inline browser) is pretty much closed on IE6. I
    guess you tried first WebBrowserControl? If not yet then to save your
    time: that was locked even prior the above.

    Are the servers you are trying to communicate between yours? What kind
    of communication are you seeking? There are some options.
     
    VK, May 1, 2006
    #3
  4. Guest

    Randy,

    Thanks alot for the info. Unfortunately what you have suggested don't
    seem to suit my need. What I need is a way to block execution until an
    activex object has finished init (my activex objcet changes the state
    of
    a member variable when it finishes init) because I don't want to start
    loading
    a java applet until the activex object has completed init (they talk to
    each
    other, and they can be different objects/applets under different
    circumstances
    or user input)

    I've noticed everytime I do a xxx.appendChild (yes I left it out,
    thought
    it was obvious), IE spawns a thread to run that, so I could not have
    done

    activexobj = document.createElement('object');
    .......
    document.appendChild(activexobj);
    scriptobj = docuemtn.create('script');
    scriptobj.text = '....';
    document.appendChild(scriptobj);

    because then the script will run in parallel of the loading of the
    activex...
    not to mention not blocking the calling thread at all... (appending the
    script elelment to the div element does help either)

    As mentioned I could not have done document.write() because it
    overwrites the page, and my stuff is done at the body after the
    page is loaded.... document.write() does block during loading because
    it is run in the same thread...

    I am quite new to javascript, I wonder if there is any other way
    to acommplish what I need - dynamically load an active object
    (not neccessarily known during load time) and block the javascript
    execution until the object has executed an init function???

    Thanks alot for you help.


    Randy Webb wrote:
    > said the following on 5/1/2006 4:32 AM:
    > > Hello,
    > >
    > > I need to dynamically load an activex object because what
    > > object to load is based on certain conditions. Also I need to
    > > wait for the object to have initialized before moving on. What I did
    > > was having the activex object set a variable and have the javascript
    > > spin on that variable (a wait function)...
    > >
    > > function load() {
    > > var newsection = document.createElement('div');
    > > var newcode = '<object codebase = ' + what_to_load() + '....><script
    > > javascript....>' +
    > > ' wait_on_new_activex_object_prop()</script>';
    > > newsection.innerHTML = newcode;

    >
    > Why are you using createElement and then trying to innerHTML something
    > into it? And, you aren't appending your newsection unless you left that
    > code out.
    >
    > > ....
    > > }
    > >
    > > Note that I did not want to overwrite the entire page by using
    > > document.write(), that is why I created a new element to
    > > load the activex object...

    >
    > You can do a document.write there if it is done while the page is loading.
    >
    > > However this code does not work, the wait javascript function
    > > wasn't executed at all (I tried to put an "alert()" there, it didnt
    > > get called either)... it looks like IE cannot execute dynamically
    > > created javascript.

    >
    > Sure it can. Just not the way you are trying to dynamically create it.
    >
    > > Is there another way to accomplish what I am trying to do? Any
    > > idea would be really helpful.

    >
    > Use createElement to create a script element, create its .text property
    > and off you go.
    >
    > var newScript = document.createElement('script');
    > newScript.text = 'alert("This is the alert")';
    > document.getElementById('someContainer').appendChild(newScript);
    >
    > But, why not use createElement to create the OBJECT tag as well?
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    , May 2, 2006
    #4
  5. VK Guest

    wrote:
    > I am quite new to javascript, I wonder if there is any other way
    > to acommplish what I need - dynamically load an active object
    > (not neccessarily known during load time) and block the javascript
    > execution until the object has executed an init function???



    In IE both <object> and <script> have onreadystatechange handler you
    can attach a listener, just like for XMLHttpRequest. The only
    difference is that the readyState is reported in the regular IE string
    notation instead of numbers:

    "uninitialized" Object is not initialized with data.
    "loading" Object is loading its data.
    "loaded" Object has finished loading its data.
    "interactive" User can interact with the object even though it is not
    fully loaded.
    "complete" Object is completely initialized.

    This way you can:

    function notifyObserver() {
    if (this.readyState = 'complete') {
    // object is loaded successfully
    }
    }

    var myObject = document.createElement('OBJECT');
    // prepare object
    myObject.onreadystatechange = notifyObserver;
    document.body.appendChild(myObject);
     
    VK, May 2, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timo Nentwig
    Replies:
    4
    Views:
    671
    Raymond DeCampo
    Nov 2, 2003
  2. moon
    Replies:
    13
    Views:
    6,641
    Gregory A. Swarthout
    Mar 5, 2004
  3. mandy
    Replies:
    14
    Views:
    10,325
    Mike Schilling
    Mar 27, 2006
  4. Lee Fesperman
    Replies:
    20
    Views:
    5,304
    Dale King
    May 22, 2006
  5. Grant H.
    Replies:
    2
    Views:
    212
    Grant H.
    Jun 9, 2004
Loading...

Share This Page