Veeery strange attribute value

S

szimek

Hi,

I've got a div with very strange attribute value. Here it is:

menudef = "module_menu,,,,[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object]"

Here's js code that fetches this attribute:
var md = menu.getAttribute("menudef"); // menu is a div element

In IE md[0] is "module_menu" and i.e. md[4] is an actual object (array-
like).

in FF3 md[0] is "m", md[1] is "o", md[2] is "d" and so on. So it
treats the whole thing as a string.

Not sure if it has any meaning, but:
- in IE I can view generated HTML using IE Developer Toolbar and I
can't see menudef attribute there (but I don't trust this tool).
However, it's displayed in element's attribute list window (that
window in the middle)
- in FF I can see the attribute directly in HTML code

How IE is able to figure out actual objects from this menudef string?!
Or is it only displayed as string in IE?
 
J

Joost Diepenmaat

szimek said:
Hi,

I've got a div with very strange attribute value. Here it is:

menudef = "module_menu,,,,[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object]"

Here's js code that fetches this attribute:
var md = menu.getAttribute("menudef"); // menu is a div element

Note that "menudef" != menudef.
In IE md[0] is "module_menu" and i.e. md[4] is an actual object (array-
like).

what's md?
in FF3 md[0] is "m", md[1] is "o", md[2] is "d" and so on. So it
treats the whole thing as a string.

Actually, while strings have array-like accessors, arrays of strings
aren't strings. IOW, you're *probably* dealing with a string,
somewhere.
Not sure if it has any meaning, but:
- in IE I can view generated HTML using IE Developer Toolbar and I
can't see menudef attribute there (but I don't trust this tool).
However, it's displayed in element's attribute list window (that
window in the middle)
- in FF I can see the attribute directly in HTML code

How IE is able to figure out actual objects from this menudef string?!
Or is it only displayed as string in IE?

I get the feeling that the assignment at the top of your post is not in
fact there in the code, and you're just presenting a toString()
representation of a nested data structure.

It may help to post *actual* code that demonstrates this problem. Not
some random stringifications of (as far as I can see) unrelated
varables.
 
S

szimek

szimek said:
I've got a div with very strange attribute value. Here it is:
menudef = "module_menu,,,,[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object]"
Here's js code that fetches this attribute:
var md = menu.getAttribute("menudef"); // menu is a div element

Note that "menudef" != menudef.
In IE md[0] is "module_menu" and i.e. md[4] is an actual object (array-
like).

what's md?
in FF3 md[0] is "m", md[1] is "o", md[2] is "d" and so on. So it
treats the whole thing as a string.

Actually, while strings have array-like accessors, arrays of strings
aren't strings. IOW, you're *probably* dealing with a string,
somewhere.
Not sure if it has any meaning, but:
- in IE I can view generated HTML using IE Developer Toolbar and I
can't see menudef attribute there (but I don't trust this tool).
However, it's displayed in element's attribute list window (that
window in the middle)
- in FF I can see the attribute directly in HTML code
How IE is able to figure out actual objects from this menudef string?!
Or is it only displayed as string in IE?

I get the feeling that the assignment at the top of your post is not in
fact there in the code, and you're just presenting a toString()
representation of a nested data structure.

It may help to post *actual* code that demonstrates this problem. Not
some random stringifications of (as far as I can see) unrelated
varables.

Thanks for quick answer. I've managed to figure out how this attribute
is generated. Damn it's strange :)

In the js file:
function menuItem(maaany parameters) {
this.parameter1 = parameter1;
this.parameter2 = parameter2;
and so on...
}

In the web page:
menuDef1 = new Array;
menuDef1[menuDef1.length]="module_menu";
....
menuDef1[menuDef1.length]=new menuItem("foo", "bar", "and so on"); //
4th element
....
buildMenu(menuDef1);

In the js file:
function buildMenu(menuDef) {
...
newMenu = document.createElement("div");
newMenu.setAttribute("menudef",menuDef);
...
}

So the whole menu is inside the web page as js code, which defines
billions of menu definitions and later creates div elements for each
menu.

I can't change the whole method of generating the menu, I'm just
trying to make it work in FF.
 
S

szimek

szimek said:
Hi,
I've got a div with very strange attribute value. Here it is:
menudef = "module_menu,,,,[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object],[object Object],[object
Object],[object Object],[object Object]"
Here's js code that fetches this attribute:
var md = menu.getAttribute("menudef"); // menu is a div element
Note that "menudef" != menudef.
In IE md[0] is "module_menu" and i.e. md[4] is an actual object (array-
like).
what's md?
in FF3 md[0] is "m", md[1] is "o", md[2] is "d" and so on. So it
treats the whole thing as a string.
Actually, while strings have array-like accessors, arrays of strings
aren't strings. IOW, you're *probably* dealing with a string,
somewhere.
I get the feeling that the assignment at the top of your post is not in
fact there in the code, and you're just presenting a toString()
representation of a nested data structure.
It may help to post *actual* code that demonstrates this problem. Not
some random stringifications of (as far as I can see) unrelated
varables.

Thanks for quick answer. I've managed to figure out how this attribute
is generated. Damn it's strange :)

In the js file:
function menuItem(maaany parameters) {
  this.parameter1 = parameter1;
  this.parameter2 = parameter2;
  and so on...

}

In the web page:
menuDef1 = new Array;
menuDef1[menuDef1.length]="module_menu";
...
menuDef1[menuDef1.length]=new menuItem("foo", "bar", "and so on"); //
4th element
...
buildMenu(menuDef1);

In the js file:
function buildMenu(menuDef) {
  ...
  newMenu = document.createElement("div");
  newMenu.setAttribute("menudef",menuDef);
  ...

}

So the whole menu is inside the web page as js code, which defines
billions of menu definitions and later creates div elements for each
menu.

I can't change the whole method of generating the menu, I'm just
trying to make it work in FF.

I guess that ability to store objects inside attrbiutes of html
elements is some magic IE-only feature.
Thus, I need something that would convert my array of objects into a
string and then back from this string to array of objects.

Using the code from the previous post:

newMenu = document.createElement("div");
newMenu.setAttribute("menudef",menuDef.toString()); // where menuDef
is an array of strings and menuItem objects, see previous post for
details

and then:

menuDef = newMenu.getAttribute("menudef").toObject();

menuDef[0] => string
menuDef[4].parameter1 => string, where menuDef[4] is menuItem object
(simple hash)

Are there some already made functions to do such conversions (JSON or
something)? If not, any tips how to write something like this? menuDef
is a simple array which can store a string or menuItem, which is a
simple hash.

Thanks in advance for any tips!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top