从applet调用JavaScript函数 [英] Calling a Javascript function from an applet
问题描述
所有我想要做的就是调用从Applet的一个JavaScript函数,并通过多个变量,我可以只用一个变量来做到这一点,但我想与多个做到这一点。
All I want to do is call a javascript function from a Applet and pass multiple variables, I'm able to do this with just one variable, but I want to do it with multiple.
这是小应用程序调用JavaScript函数并传递一个变量其中工程:
calling Javascript function from applet and passing one variable which works:
msg = "test";
try {
getAppletContext().showDocument
(new URL("javascript:UpdateComputerDetails(\"" + msg + "\")"));
}
catch (MalformedURLException me) { }
我如何可以传递多个变量来这个功能呢?
How Can I pass Multiple variables to this function?
推荐答案
您将简单地想用:
arg1 = "foo";
arg2 = "bar";
try {
getAppletContext().showDocument
(new URL("javascript:UpdateComputerDetails(\"" + arg1 + "\", \"" + arg2 + "\")"));
}
catch (MalformedURLException me) { }
在艰难的部分掌握实际上是构建URL,因为你将不得不逃避一些东西以这种或那种方式。您可以通过在JS使用单引号缓解疼痛:
The tough part to master is actually building the URL, since you'll have to escape some stuff in one way or another. You can ease the pain by using single-quotes in the JS:
"javascript:UpdateComputerDetails('" + arg1 + "', '" + arg2 + "')"
现在,你必须要小心, ARG1
和 ARG2
(如果你去多了,其他参数以及)要么不包含
(或如果您使用双引号语法),或这些你建立你的URL,然后进行正确转义。
Now, you need to be careful that arg1
and arg2
(and if you go for more, the other arguments as well) either do not contain '
(or "
if you use the double-quote syntax), or these are properly escaped before you build your URL.
这篇关于从applet调用JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!