Waiting for ActiveX object to have initialized

M

marcosnogood

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.
 
R

Randy Webb

(e-mail address removed) 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?
 
V

VK

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.
 
M

marcosnogood

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.
 
V

VK

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);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top