开发者

error when calling applet method with javascript

i want to read network card identity of a machine using applet that only works on jre 1.6 & above. even applet loaded sucessfully开发者_如何学Python on page loading , i was not able to call Applet methods with javascript. when i checked the applet functions by calling javascipt from button, it was working as expected. why i could not call applet function on load.

i found one error on IE " Object doesn't support this property or method"

below code working fine with firefox but not working with IE6 & 7


 ** script  **

function getMAC(){

      try{
        var a=null;
        var obj=null;
        a=document.getElementById('jsap').readMACaddress();
  alert('mac address:'+a);
      }catch(e){
  alert('error::'+e);
      }

}
 ** /script **

  ** object type="application/x-java-applet"
  classid="clsid:CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA" 
 width= "180" height= "180"  name="jsap" id="jsap" 

   **param name="archive" value="macaddr.jar" 
  **param name="code" value="com/mac/GeneralApplet" 
  **param name="mayscript" value="yes" 
  **param name="scriptable" value="true" 
 **/object 


 **input type="button" name="getmac" value="show" onclick="getMAC();" **


 **script **

 getMAC();

 **/script **

please help me

Thanks Yohi


Perhaps you are missing the CLASSID attribute of the object tag? Also try changing the function to use document.getElementById

function getMAC(){
   // ...
   a=document.getElementById("jsap").readMACaddress();
   // ...
}  

More about the classId attribute is documented here


According to http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/guides/plugin/developer_guide/java_js.html, syntax changes from object, applet and embed tags. The 'MAYSCRIPT' attribute should be uppercase (maybe case matters).

I'd try using 'true' instead of 'yes' as suggested by the same page above.

I seem to recall that you need to use MAYSCRIPT as an attribute instead of a parameter, with IE. So I'd try something like

<object type="application/x-java-applet"
  classid="clsid:CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA" 
 width= "180" height= "180"  name="jsap" id="jsap" MAYSCRIPT="true" >
  <param name="archive" value="macaddr.jar" />
  <param name="code" value="com/mac/GeneralApplet"  />
  <param name="MAYSCRIPT" value="true" />
  <param name="scriptable" value="true" />
</object>

Also, you mention (if I understood correctly) that the problem happens at load time. Try calling your method from the onLoad event of the body element, which should ensure that every resource has been loaded before being triggered.

<body onLoad="yourCode();" />

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜