javascript waiting for activex to load before execting

G

Grant H.

hi all,

i have a strange problem here & i'm not sure how to go about fixing
it. Basically, I have a page with an activex control that gets launch
with JS when a user clicks a "connect" button. Now, all i want to do
is disable the button & change the text while the activex is loading.
now, the code below should work, but what i'm seeing is that the js
doesn't even start executing until the activex is loaded. so, what i'm
expecting is the js to run down the function sequentially so:

-the first 2 lines disable & change the text of the button
-the active loads (the button is still disabled)
-activex done load & i re-enable the button.

what actually happens is: when i hit the button, it sits there & loads
the activex, then runs down the function so the disable & re-enable of
the buttons go really fast. any help would be appriciated!

thanks!

-grant.

<object id="MyAppLaunch" type="application/x-oleobject"
classid="CLSID:8E0FDFBC-77D4-43a1-9AD4-41F0EA8AFF7C"
codebase="myapp.cab#version=2,1,0,1">
</object>
<script language="javascript">
<!--

function DoIt()
{
document.form1.Connect.value = "Please Wait...";
document.form1.Connect.disabled = true;

try{
MyAppLaunch.Launch(1,2,3,4,5);
}catch(oException){window.location.href="myapp.exe";}
}
document.form1.Connect.value = "Connect";
document.form1.Connect.disabled = false;
}
-->
</script>
 
V

Vincent van Beveren

Hi grant,
what actually happens is: when i hit the button, it sits there & loads
the activex, then runs down the function so the disable & re-enable of
the buttons go really fast. any help would be appriciated!

The problem is the way the browser handels its GUI updates. While
running your script, there is no point where control is handed back
to the browser so it can repaint. Therefor the best thing is to make
a small delay in your execution to give the browser some time to repaint
before initializing your object.

function DoIt()
{
document.form1.Connect.value = "Please Wait...";
document.form1.Connect.disabled = true;
window.setTimeout("finishIt();",100);
}

function FinishIt() {

try{
MyAppLaunch.Launch(1,2,3,4,5);
}catch(oException){
window.location.href="myapp.exe";}
}
document.form1.Connect.value = "Connect";
document.form1.Connect.disabled = false;
}

-->
</script>

That should do it.

Good luck,
Vincent
 
G

Grant H.

Hi Vincent,

you're absolutely right! I put the setTimeout in there & it works like
a charm. thanks!!

-grant
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top