is this a safe way to do it and is it the most compatible?
It's only as safe as the client is safe, so you should assume that the client may edit/forge/hack, etc.
If you meant safe in the other sense - not causing conflict - use an Object as your namespace in JavaScript and have everything kept within that Object. This way you are much less likely to have trouble with any conflicting variable names elsewhere on a page. You may also want to use unobtrusive JavaScript, to keep your script and HTML independent of each other.
Currently, your function hello
is in the global namespace, and creates a global result
, which could cause conflicts.
Assuming that the client has an up-to-date copy of Java and plugins enabled, you only really need to worry about the same compatibility issues as when writing any normal JavaScript for any browser.