How can I embed a Java applet dynamically with Javascript?

前端 未结 6 621
我寻月下人不归
我寻月下人不归 2021-01-02 03:13

I want to be able to insert a Java applet into a web page dynamically using a Javascript function that is called when a button is pressed. (Loading the applet on page load

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 03:46

    Create a new applet element and append it to an existing element using appendChild.

    var applet = document.createElement('applet');
    applet.id = 'player';
    

    ...

    var param = document.createElement('param');
    

    ...

    applet.appendChild(param);
    document.getElementById('existingElement').appendChild(applet);
    

    Also, make sure the existing element is visible, meaning you haven't set css to hide it, otherwise the browser will not load the applet after using appendChild. I spent too many hours trying to figure that out.

提交回复
热议问题