How to use JavaScript to call Activex control events

Source: Internet
Author: User

Written as follows:

<SCRIPT type = "text/javascript" FOR = "activexID" EVENT = "onXXXevent ()">
// Js processing specific content.
</SCRIPT>
This method is called when the onXXXevent () event of the acitveX control is triggered.

If you have a half, dozens of such functions fill up my pages. Besides, in VS2008, "setting selected content formatting" always prompts "failed to complete this operation ".
So I want to use another method to replace this writing. At the very least, I can put it in a separate js file.

Copy codeThe Code is as follows:
Vbscript implementation is very strange
Sub activex_onXXXevent ()
'Process specific content
End sub

I didn't understand.
Copy codeThe Code is as follows:
<Script type = 'text/javascript '>
Function onXXXevent (){
// Js content
}
ActivexID. attachEvent ("onXXXevent", onXXXevent );
</Script>

Oh, this method can be perfectly implemented, and can be put into a JS file. VS2008 can also support it.
Record the attachEvent content by the way
In recent work, the attachEvent method is used. This method can append other processing events to an event, which may be useful sometimes. Here we will summarize its basic usage.
For more information about its syntax, see the DHTML manual. Here is an example from the Internet:
Copy codeThe Code is as follows:
Document. getElementById ("btn"). onclick = method1;
Document. getElementById ("btn"). onclick = method2;
Document. getElementById ("btn"). onclick = method3;

If this is the case, only medhot3 will be executed.
Write as follows:
Copy codeThe Code is as follows:
Var btn1Obj = document. getElementById ("btn1 ");
// Object. attachEvent (event, function );
Btn1Obj. attachEvent ("onclick", method1 );
Btn1Obj. attachEvent ("onclick", method2 );
Btn1Obj. attachEvent ("onclick", method3 );

The execution sequence is method3-> method2-> method1

If the Mozilla series does not support this method, you need to use addEventListener.
Copy codeThe Code is as follows:
Var btn1Obj = document. getElementById ("btn1 ");
// Element. addEventListener (type, listener, useCapture );
Btn1Obj. addEventListener ("click", method1, false );
Btn1Obj. addEventListener ("click", method2, false );
Btn1Obj. addEventListener ("click", method3, false );

The execution sequence is method1-> method2-> method3

Related Article

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.