2009-07-20 45 views
2

我在我的網站中有下一個代碼。此代碼是c#activex,函數警報(MyCC.GetID()。Fullname)有效,但事件不起作用。我做錯了什麼?ActiveX事件在javascript中不起作用

<object id="MyCC" codebase="http://localhost:3239/WebDAVCab.CAB" 
    classid="clsid:5F9A5DDB-0D35-4893-A9ED-1FAFFE94373A" width="80" height="120" VIEWASTEXT> 
</object> 

<script type="text/javascript"> 
     MyCC = document.getElementById("MyCC"); 
     alert(MyCC.GetID().Fullname); 

     MyCC.CardInserted = OnCardInserted; 
     MyCC.CardRemoved = OnCardRemoved; 

     function OnCardInserted() 
     { 
      alert("raised"); 
     } 
     function OnCardRemoved() 
     { 
      alert("raised2"); 
     } 
    </script> 

回答

1

的正確語法沉沒在Javascript這些事件如下:

function MyCC::CardInserted() { } 

MyCC::CardInserted = function() { } 

當然,你不必指定一個匿名函數:

MyCC::CardInserted = OnCardInserted; 
+0

我測試過但在MyCC中返回錯誤::我得到一個ie錯誤預期; – pedrofernandes 2009-07-21 11:20:49

0
  1. 嘗試使用MyCC.attachEvent('CardInserted', OnCardInserted);代替
  2. 您還需要實現IObjectSafety
+0

我試過但沒有着火。在windows窗體中引入這個控件並且工作得很好,所有的事件都是在windows窗體中觸發的,但是在html/javascript中沒有。 – pedrofernandes 2009-07-20 12:59:43

1

爲了將事件附加到ActiveX可以使用安迪e系統解決方案,但EVAL:

<object name="MyCC" id="MyCC" codebase="http://localhost:3239/WebDAVCab.CAB" 
    classid="clsid:5F9A5DDB-0D35-4893-A9ED-1FAFFE94373A" width="80" height="120" VIEWASTEXT> 
</object> 

<script type="text/javascript"> 

    eval("function MyCC::CardInserted() {return OnCardInserted();}"); 
    eval("function MyCC::CardRemoved() {return OnCardRemoved();}"); 

    function OnCardInserted() 
    { 
     alert("raised"); 
    } 
    function OnCardRemoved() 
    { 
     alert("raised2"); 
    } 
</script> 
相關問題