Discussion:
how to get dom-node's attribute set by javascript code.
pengdawei
2009-12-23 02:34:34 UTC
Permalink
javascript code:

<script>
function setuattr()
{
var div1 = document.getElementById("output");
div1.setAttribute ("zz0", "zz0-attribute");
div1.zz1 = "zz1-attribute";
}
</script>
<body onload="setuattr()">
<div id="output"></div>

when then page finished loading, I can get the zz0 attribute through nsIDOMElement interface in c++.
but I can't get the zz1 attribute.

in Firebug, the difference is:

zz0 is in dom node's attribute
<div id="output" zz0="zz0-attribute"/>

but zz1 is in Firebug's DOM panel, I checked firebug's code, and firebug get zz1 by using " for var a in object"

can any one tell me how to get zz1 attribute in C++?

thanks.
Boris Zbarsky
2009-12-23 03:52:03 UTC
Permalink
Post by pengdawei
div1.zz1 = "zz1-attribute";
That's a pure JS property, not a DOM property.
Post by pengdawei
when then page finished loading, I can get the zz0 attribute through nsIDOMElement interface in c++.
but I can't get the zz1 attribute.
Correct; that zz1 thing is not present in the DOM at all. It's present
only in JavaScript, as a property of the JavaScript reflection of that
<div>'s DOM Node.
Post by pengdawei
but zz1 is in Firebug's DOM panel
Firebug's so-called "DOM" panel isn't. It's a JS object viewer.
Post by pengdawei
can any one tell me how to get zz1 attribute in C++?
Using JSAPI (JS_GetProperty and the like).

-Boris
zz
2009-12-23 04:06:10 UTC
Permalink
Post by Boris Zbarsky
Post by pengdawei
div1.zz1 = "zz1-attribute";
That's a pure JS property, not a DOM property.
Post by pengdawei
when then page finished loading, I can get the zz0 attribute through
nsIDOMElement interface in c++.
but I can't get the zz1 attribute.
Correct; that zz1 thing is not present in the DOM at all. It's present
only in JavaScript, as a property of the JavaScript reflection of that
<div>'s DOM Node.
Post by pengdawei
but zz1 is in Firebug's DOM panel
Firebug's so-called "DOM" panel isn't. It's a JS object viewer.
Post by pengdawei
can any one tell me how to get zz1 attribute in C++?
Using JSAPI (JS_GetProperty and the like).
-Boris
thank you very much, Boris!

now I want to dump these JS property of a (nsIDOMElement *aElement).
please tell me which api-file should I check to do this.

that is when there is a (nsIDOMElement *aElement), how to use
JS_GetProperty to get the JS property, please tell me some class names,
cpp filenames to look into.

thanks.
Boris Zbarsky
2009-12-23 04:20:08 UTC
Permalink
Post by zz
that is when there is a (nsIDOMElement *aElement), how to use
JS_GetProperty to get the JS property, please tell me some class names,
cpp filenames to look into.
There isn't a particularly nice API for it. You'll have to ask
nsIXPConnect for the JS wrapper for that object, then use the API
functions in jsapi.h to look for things on it.

-Boris
pengdw
2009-12-23 07:44:40 UTC
Permalink
Post by Boris Zbarsky
Post by zz
that is when there is a (nsIDOMElement *aElement), how to use
JS_GetProperty to get the JS property, please tell me some class names,
cpp filenames to look into.
There isn't a particularly nice API for it. You'll have to ask
nsIXPConnect for the JS wrapper for that object, then use the API
functions in jsapi.h to look for things on it.
-Boris
done.

first, I convert nsIContent *content to a jsval,
then use JS_GetProperty to get the JS property and output.

thanks, Boris.

Continue reading on narkive:
Loading...