袁瑞's profile袁瑞的共享空间PhotosBlogGuestbookMore Tools Help

Blog


    24 March

    在DHTML中响应ActiveX控件的事件

    转载自www.diybl.com  作者:佚名

    ActiveX控件可以用连接点创建事件,此事件可以在DHTML网页中被javascript函数处理,在js中响应ActiveX控件事件的方法如下:
    1. 静态创建方法     
    <script>
    function  OnEvent1()
    {
    }
    </script>
    <OBJECT id="myControl"
                       codeBase="myControl.cab"              
                       classid="clsid:1ACA02DF-AF52-4371-89B9-B9245BD21831"
    ></OBJECT>
    <script       language=javascript
                       FOR="myControl"
                       EVENT="event1()">   
                       OnEvent1();
    </script>
    2. 动态创建方法
    function onBodyLoad()
    {
            myControl = document.createElement("OBJECT");
            document.body.appendChild(myControl);
            myControl.codeBase = "myControl.cab";
            myControl.classid = "clsid:1ACA02DF-AF52-4371-89B9-B9245BD21831";
            myControl.attachEvent("event1", OnEvent1);
    }
    <body onload="onBodyLoad()">
    ...
    3. 错误的动态创建方法
    function onBodyLoad()
    {
            myControl = new ActiveXObject(myControl.Test);
            myControl.attachEvent("event1", OnEvent1);
            ~~~~~~~~~~~~~~~~~~此时会报告“无此方法”,这是因为
    用new ActiveXObject创建的对象并非一个DOM对象,因此不能
    调用attachEvent方法。而用document.createElement("OBJECT")
    创建的才是一个DOM对象。
    }
    <body onload="onBodyLoad()">

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://yuanreid.spaces.live.com/blog/cns!B8B62901E38AB827!379.trak
    Weblogs that reference this entry
    • None