1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[js] innerHTML (setter)

This commit is contained in:
Witold Filipczyk 2021-06-03 11:59:15 +02:00
parent 07fccc9f87
commit 5de45a9e96
2 changed files with 42 additions and 0 deletions

View File

@ -46,6 +46,8 @@
#include "viewer/text/link.h"
#include "viewer/text/vs.h"
#include <libxml/tree.h>
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#include <libxml++/attributenode.h>
@ -1467,6 +1469,21 @@ element_set_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
xmlpp::Element *el = JS_GetPrivate(hobj);
if (!el) {
return true;
}
auto children = el->get_children();
auto it = children.begin();
auto end = children.end();
for (;it != end; ++it) {
xmlpp::Node::remove_node(*it);
}
char *text = JS_EncodeString(ctx, args[0].toString());
el->add_child_text(text);
return true;
}

View File

@ -0,0 +1,25 @@
<html>
<body>
<a href="/home">BBB</a>
<b id="aaaa">bbb</b>
<a id="blabla" href="/">
<b>AAA</b><u id="ble">UUU</u>AAAAAAA
</a>
<a id="bb" href="/">BB</a>
<script>
function aa()
{
alert(document.getElementById('blabla').innerHTML);
alert(document.getElementById('ble').innerHTML);
}
function bb()
{
document.getElementById('blabla').innerHTML = '<u>test</u>';
alert(document.getElementsByTagName("HTML")[0].outerHTML);
}
</script>
<button onclick="return aa()">Click me!</button>
<button onclick="return bb()">innerText test</button>
</body>
</html>