is there a way to access the DOM from a EMSCRIPTEN C++ application?
I'd like e.g., to read / set the value of an html textarea and receive html buttons onclick events.
Can someone provide a C++ snippet?
Thanks.
I'll try to answer my own question with the only method I found by now:
this is the html snippet:
<!-- html file -->
...
<input type="text" id="my_textbox" value="...">
...
<input type="submit" value="Submit" onclick="_onBtnPressed()">
...
and this is the C++ code:
// C++ file
// callback for button event
extern "C"
{
void onBtnPressed() { std::cout << "Btn pressed\n"; }
}
...
// change text of a text box:
emscripten_run_script("document.getElementById('my_textbox').value = 'Hello, emscripten world!'");
Compiled with the flag:
emcc -s EXPORTED_FUNCTIONS="['_onBtnPressed']" ...
This method works. However, I'd expect some explicit emscripten API to directly manipulate the DOM.
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