JavaScript和Applet通訊

來源:互聯網
上載者:User
1、Javascript要訪問的Applet的方法或屬性必須都是public的 

2、在html中給applet的name屬性賦值,以前是用applet標籤,現在要用object,也是一樣,如下(看紅色name屬性): <OBJECT
    classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,7"
    WIDTH = 600 HEIGHT = 470 name="browseFileApplet">
    <PARAM NAME = CODE VALUE = "com.jointforce.applet.browsefile.BrowseFileApplet.class" >
    <PARAM NAME = ARCHIVE VALUE = "browsefileapplet.jar" >
    <PARAM NAME = "type" VALUE = "application/x-java-applet;version=1.4">
    <PARAM NAME = "scriptable" VALUE = "false">
    <PARAM NAME = username VALUE="<%=username%>">
    <PARAM NAME = socketserverip VALUE="<%=ssip%>">
    <PARAM NAME = socketserverport VALUE="<%=ssport%>">
    <PARAM NAME = sockettimeout VALUE="<%=sto%>">
    <PARAM NAME = userhomedirectory VALUE="<%=uhd%>">

    <COMMENT>
<EMBED
            type = "application/x-java-applet;version=1.4" \
            CODE = "com.jointforce.applet.browsefile.BrowseFileApplet.class" \
            ARCHIVE = "browsefileapplet.jar" \
            WIDTH = 600 \
            HEIGHT = 470 \
            name = "browseFileApplet" \
            username ="<%=username%>" \
            socketserverip ="<%=ssip%>" \
            socketserverport ="<%=ssport%>" \
            sockettimeout ="<%=sto%>" \
            userhomedirectory ="<%=uhd%>" \
     scriptable = false \
     pluginspage = "http://java.sun.com/products/plugin/index.html#download">
     <NOEMBED>
    
            </NOEMBED>
</EMBED>
    </COMMENT>
</OBJECT>

 

3、在javascript中直接就可以訪問了,如下: 

function okbtnpressed() {
    // current selection is a directory or a file? getCurrentSel是applet的一個方法
    var currentSel = window.document.browseFileApplet.getCurrentSel();
    if (currentSel == "OK") {
        window.opener.document.SubmitTaskForm.executable.value = window.document.browseFileApplet.result;  //result是applet的一個成員變數
        window.opener = null;
        return window.close();
        return false;
    } else {
        alert("請選擇一個檔案!");
        return false;
    }
}

 

這種方法只在IE中有效,在Firefox中無效。後面將有一篇文章談到如何在Firefox和IE中都能讓JavaScript和JAVA通訊。 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.