1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

[js] document.documentElement

This commit is contained in:
Witold Filipczyk 2021-05-12 17:22:34 +02:00
parent 937b77cfdf
commit 51fe9d1968
2 changed files with 63 additions and 0 deletions

View File

@ -228,6 +228,48 @@ document_set_property_cookie(JSContext *ctx, unsigned int argc, JS::Value *vp)
#endif
static bool
document_get_property_documentElement(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
JS::CallArgs args = CallArgsFromVp(argc, vp);
JSCompartment *comp = js::GetContextCompartment(ctx);
struct ecmascript_interpreter *interpreter = JS_GetCompartmentPrivate(comp);
struct document_view *doc_view = interpreter->vs->doc_view;
struct document *document = doc_view->document;
if (!document->dom) {
document->dom = document_parse(document);
}
if (!document->dom) {
args.rval().setNull();
return true;
}
xmlpp::Element* root = (xmlpp::Element *)document->dom;
std::string xpath = "//html";
xmlpp::Node::NodeSet elements = root->find(xpath);
if (elements.size() == 0) {
args.rval().setNull();
return true;
}
auto element = elements[0];
JSObject *html = getElement(ctx, element);
if (html) {
args.rval().setObject(*html);
} else {
args.rval().setNull();
}
return true;
}
static bool
document_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
{
@ -500,6 +542,7 @@ JSPropertySpec document_props[] = {
#ifdef CONFIG_COOKIES
JS_PSGS("cookie", document_get_property_cookie, document_set_property_cookie, JSPROP_ENUMERATE),
#endif
JS_PSG("documentElement", document_get_property_documentElement, JSPROP_ENUMERATE),
JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE),
JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE),
JS_PSGS("title", document_get_property_title, document_set_property_title, JSPROP_ENUMERATE), /* TODO: Charset? */

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<body id="test">
<button onclick="myFunction()">Try it</button>
<a href="/">/</a>
<a href="/home">/home</a>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.documentElement.innerHTML;
alert(x);
}
</script>
</body>
</html>