Conditional loading of ActiveX events when ActiveX is used
When ActiveX is used, events are directly added to the page. For example:
1) Call voice TTS ActiveX
< Script Type = "Text/JavaScript" Language = "JavaScript" >
VaR Voiceobj = Null ; // TTS object
Voiceobj = New Activexobject ( ' SAPI. spvoice ' );
</ Script >
2) Add the audio ActiveX playback completion event at the bottom of the page.
< Script Type = "Text/JavaScript" Language = "JavaScript" >
Function Voiceobj: endstream ()
{
Oldttscount -- ;
}
</ Script >
But the problem arises. When you use a page with ActiveX, you are prompted whether to load ActiveX. If ActiveX is not loaded, an error is reported. In this case, we should determine whether the user has loaded ActiveX, and add ActiveX-related events when the user has loaded ActiveX. The solution is as follows.
1) when loading, you can identify ActiveX loading by capturing exceptions.
< Script Type = "Text/JavaScript" Language = "JavaScript" >
VaR Voiceobj = Null ; // TTS object
If (Voiceobj = Null ){
Try {
Voiceobj = New Activexobject ( ' SAPI. spvoice ' );
} Catch (ERR ){
Voiceobj = Null ;
}
}
</ Script >
2) When the ActiveX object is null, the object is not loaded.
< Script Type = "Text/JavaScript" Language = "JavaScript" >
VaR Ttsfn = Function (){
Function Voiceobj: endstream ()
{
// Run its content
}
}
If (Voiceobj ! = Null ){
// Load ActiveX events
Ttsfn ();
}
</ Script >