472,141 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

Waiting for ActiveX object to have initialized

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 '06 #1
4 5521
ma**********@lycos.com 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').appendChi ld(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 1 '06 #2
VK

ma**********@lycos.com 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.

May 1 '06 #3
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:
ma**********@lycos.com 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').appendChi ld(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 '06 #4
VK

ma**********@lycos.com 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);

May 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by AnalogKid | last post: by
106 posts views Thread by A | last post: by
5 posts views Thread by Hansen | last post: by
5 posts views Thread by NPotnis | last post: by
2 posts views Thread by abhimanyu | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.