Why isn't this printing?

M

Mark

<script>
var
kw,dsc,w=window,d=document,e=encodeURIComponent,m=d.getElementsByTagName("meta");
for(var i in m) {
var n=m.name.toLowerCase(),c=m.content;
if(n=="keywords") kw=c;
if(n=="description") dsc=c;
d.write(kw+"<br/>");
}
d.write("hello?");
</script>

The keywords print as expected, but "hello" never gets printed...seems
like nothing gets executed after that last }, and I just can't figure
out why. Help?
 
M

Mark

<script>
var
kw,dsc,w=window,d=document,e=encodeURIComponent,m=d.getElementsByTagName("meta");
for(var i in m) {
var n=m.name.toLowerCase(),c=m.content;
if(n=="keywords") kw=c;
if(n=="description") dsc=c;
d.write(kw+"<br/>");}

d.write("hello?");
</script>

The keywords print as expected, but "hello" never gets printed...seems
like nothing gets executed after that last }, and I just can't figure
out why. Help?


I still have no idea why it was doing that, but if I replace the for
loop with this, it fixes it for some reason...

for(var i=0;i<m.length;i++) {

(maybe it was getting into an infinite loop??)
 
K

kindy

in the for in loop,
the property "length" will operate.
so, m["length"] is just a number, so m["length"].content will cause
some error,

and, anything after for in loop is ignored.
 
T

Thomas 'PointedEars' Lahn

kindy said:
in the for in loop,
the property "length" will operate.
so, m["length"] is just a number, so m["length"].content will cause
some error,

and, anything after for in loop is ignored.

Not quite. m["length"].content evaluates to `undefined', and may cause
merely a warning -- the number is converted to a Number object for the
property access. The error that causes the rest to be disregarded would be
caused by the call to m.name.toLowerCase() instead. Since
m["length"].name evaluates to `undefined' as well, and `undefined' has no
properties, a TypeError exception is thrown, and as that is not catched, a
fatal error occurs.

Please work on your posting style, it is hardly legible.


PointedEars
 

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

Similar Threads


Members online

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top