-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyjs.java
More file actions
49 lines (34 loc) · 1.34 KB
/
Myjs.java
File metadata and controls
49 lines (34 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import ca.weblite.webview.WebView;
import ca.weblite.webview.WebViewCLI;
public class Myjs{
public static void main(String[] args){
Context ctx = Context.enter();
Scriptable scope = ctx.initStandardObjects();
Object wrappedOut = Context.javaToJS(System.out, scope);
String jsstr = "var a=1;a";
Object result = ctx.evaluateString(scope, jsstr, null, 0, null);
//System.out.print(result);
ScriptableObject.putProperty(scope, "out", wrappedOut);
jsstr = "out.print(a);<a><b>123</b></a>";
result = ctx.evaluateString(scope, jsstr, null, 0, null);
System.out.print(result);
/*
String func = "java_cb(111)";
String job = "<script type='application/javascript'>"+func+"</script>";
String html = "data:text/html,<html><body>123</body>"+job+"</html>";
WebView wv = new WebView();
wv.addJavascriptCallback("java_cb", message -> {
System.out.print(message);
new Thread(() -> {
wv.dispatch( ()-> {
wv.eval("document.write(333)");
});
}).start();
});
wv.url(html);
wv.show();*/
}
}