problem with regular expressions, IE vs. firefox

C

cjl

Hey all:

Given the following code:

var ct_series = [21,23]
var cr_series = [12]

function preload()
{
for ( parm in window )
{
if ( parm.match('_series') )
{
alert("Found one!");
}
}
}

In firefox and mozilla I get the alerts, in IE I do not.

If I try:

function preload()
{
for (parm in window)
{
alert("Found one:" + parm);
}
}

I see the alerts in IE, so I know that IE can iterate through the
window object. But none of the alert boxes show cr_series or
ct_series. In fact, this same code in Firefox results in roughly three
times as many alerts, listing objects that were not listed when run
through IE.

Help?

-CJL
 
C

cjl

Hey all:

If you've read this far, you realize that my subject line is wrong.

This is not a problem with regular expressions, but a problem with my
understanding of the window object.

I though global variables were attributes of the window object that I
could iterate through?

Maybe I should repost (double post) with a correct subject line.

-CJL
 
L

Lee

cjl said:
Hey all:

Given the following code:

var ct_series = [21,23]
var cr_series = [12]

function preload()
{
for ( parm in window )
{
if ( parm.match('_series') )
{
alert("Found one!");
}
}
}

In firefox and mozilla I get the alerts, in IE I do not.
I see the alerts in IE, so I know that IE can iterate through the
window object. But none of the alert boxes show cr_series or
ct_series. In fact, this same code in Firefox results in roughly three
times as many alerts, listing objects that were not listed when run
through IE.

The for..in loop doesn't show all of the attributes of the object.
Different browsers can, and apparently do, choose to make different
attributes visible to it.

You might be better off using a custom Object. All attributes that
you add to a custom object are visible to for..in:

var global=new Object();
global.ct_series = [21,23]
global.cr_series = [12]

function preload()
{
msg="<html><body>";
for ( parm in global )
 
C

cjl

Lee:

Thank you, that makes sense, I wasn't sure. So I guess IE doesn't make
global variables visible to it.

And I guess by creating a custom object, my for loop iterates through
considerably fewer items and not all of the attributes of the window
object, which is nice.

-CJL
 

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
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top