Conditional loading of ActiveX events when ActiveX is used

Source: Internet
Author: User
Tags sapi

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 >

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.