Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Waiting for ActiveX object to have initialized

Reply
Thread Tools

Waiting for ActiveX object to have initialized

 
 
marcosnogood@lycos.com
Guest
Posts: n/a
 
      05-01-2006
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.

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      05-01-2006
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/
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      05-01-2006

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.

 
Reply With Quote
 
marcosnogood@lycos.com
Guest
Posts: n/a
 
      05-02-2006
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').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/


 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      05-02-2006

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why this error of "variable might not have been initialized"? mandy Java 14 03-27-2006 07:26 PM
ActiveX apologetic Larry Seltzer... "Sun paid for malicious ActiveX code, and Firefox is bad, bad bad baad. please use ActiveX, it's secure and nice!" (ok, the last part is irony on my part) fernando.cassia@gmail.com Java 0 04-16-2005 10:05 PM
javascript waiting for activex to load before execting Grant H. Javascript 2 06-09-2004 03:25 AM
variable might not have been initialized moon Java 13 03-05-2004 05:14 PM
final field may not have been initialized Timo Nentwig Java 4 11-02-2003 04:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57