mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[js] document.head
This commit is contained in:
parent
51fe9d1968
commit
ed3a11b288
@ -270,6 +270,48 @@ document_get_property_documentElement(JSContext *ctx, unsigned int argc, JS::Val
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
document_get_property_head(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 = "//head";
|
||||
xmlpp::Node::NodeSet elements = root->find(xpath);
|
||||
|
||||
if (elements.size() == 0) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
auto element = elements[0];
|
||||
|
||||
JSObject *head = getElement(ctx, element);
|
||||
|
||||
if (head) {
|
||||
args.rval().setObject(*head);
|
||||
} else {
|
||||
args.rval().setNull();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
document_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
@ -543,6 +585,7 @@ JSPropertySpec document_props[] = {
|
||||
JS_PSGS("cookie", document_get_property_cookie, document_set_property_cookie, JSPROP_ENUMERATE),
|
||||
#endif
|
||||
JS_PSG("documentElement", document_get_property_documentElement, JSPROP_ENUMERATE),
|
||||
JS_PSG("head", document_get_property_head, 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? */
|
||||
|
23
test/ecmascript/head.html
Normal file
23
test/ecmascript/head.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>HEAD</title>
|
||||
</head>
|
||||
<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.head.innerHTML;
|
||||
alert(x);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user