There are a lot of great samples how to use HTML5 with VRED.
Unfortunately none of them shows how to access the data parameter of the following python code in JavaScript
sendToWebEngine( name, event, data )
VRED uses a so called CustomEvent to talk to the WebEngine. I was successfully accessing the data parameter from python as the .detail member of the JavaScript event like this:
document.addEventListener("SET_TEXT1", function(evt) { document.getElementById("hudText1").innerText = evt.detail; });
Hello, I'm trying to display the data parameter on my browser.
I tried this but it did not work.
sendToWebEngine("SizeValue", "ValueX", str(XValue))
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>SIZE</h1>
<script>
document.addEventListener("ValueX", function(evt) {
ValueX= document.getElementById("XValue").innerText = evt.detail;
});
document.write(ValueX);
</script>
</body>
</html>
Dear Ayoub,
your attempt is wrong in many levels. Let me try to both give you running code for your use case and also explain how it works.
Python side needs to look like this:
sendToWebEngine(nameOfEngine, "SET_SIZE", "x="+str(xSize)+", y="+str(ySize))
HTML side should look like this:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>SIZE</h1>
<span id="sizeValue">to be replaced by event listener</span>
<script>
document.addEventListener("SET_SIZE", function(evt) {
document.getElementById("sizeValue").innerText = evt.detail;
});
</script>
</body>
</html>
Can't find what you're looking for? Ask the community or share your knowledge.