Huh, this is a messy one. And nothing that you can do about.
source:
https://forums.oracle.com/forums/thread.jspa?threadID=2324342
So, one should take care of the fact when running the
deployJava.runApplet, (as it uses document.write) within a function or
script on already loaded page, the whole page will be rewritten with
new html written with document.write.