I have an HTML file with a simple JavaScript function, and I want to call this existing JavaScript function from my Java method using CodeName One library.
<!DOCTYPE html>
<html>
<head>
<title>who cares?</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function setName(name)
{
document.getElementById("nameLabel").innerHTML = name;
}
</script>
</head>
<body>
<div>
peace be upon you, you are welcomed : <span id="nameLabel"
style="color: blue;"></span>
</div>
</body>
</html>
So my question is how to call setName(name) function from Java code using CodeName One.
Although I found related questions and answers such as one this but I didn't find what I want!
Finally I found it
JavascriptContext context;
//initialization of [context] and loading HTML
JSObject window = context.getWindow();
window.call("setName", new Object[]
{
"Moslim"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With