...

View Full Version : Resolved [SOLVED] Variable returns correctly in FF, incorrect in Chrome



kberry
12-22-2011, 05:39 AM
Hi,

I have a global variable that I change depending on what's going on in screen.

<script>
var closed=true;
....
hideInfobox(pinInfobox);
alert("closed: " + closed) //returns false in Chrome, true in FF
</script>

And that function changes that variable.

function hideInfobox(pinInfobox)
{
if(pinInfobox != null)
pinInfobox.setOptions({ visible: false });
alert("closed: " + closed) //returns false in Chrome, false in FF
closed=true;
alert("closed: " + closed) //returns false in Chrome, true in FF
current_pid=null;
}


For some reason, in FF, it modifies the variable as expected. But in Chrome, it doesn't. Why is this? Is there any way to have consistent behaviour in both browsers?

Thanks for reading!

~ kberry

Edit: In fact:

var closed=true;
alert("closed: " + closed);

returns true in FF, but false in Chrome... why....? *sigh*

Old Pedant
12-22-2011, 07:55 AM
I would bet a latte that closed is a keyword in Chrome JavaScript.

Try just changing it to Closed or isClosed and see what happens.

In fact, let me do that now.


<script>
var closed = true;
var isClosed = true;
var Closed = true;

alert("closed: " + closed + "\nisClosed: " + isClosed + "\nClosed: " + Closed);
</script>

Yep, all "true" in FF, but "closed" is false in Chrome. And if you care, all "true" in MSIE9.

kberry
12-22-2011, 10:38 PM
That did the trick! I wonder why that is... perhaps 'closed' is a keyword in Chrome or something?

Thanks for your help!

Old Pedant
12-22-2011, 11:36 PM
That did the trick! I wonder why that is... perhaps 'closed' is a keyword in Chrome or something?

Well, either that or it might be what I said:


I would bet a latte that closed is a keyword in Chrome JavaScript.


<grin/>

Logic Ali
12-23-2011, 12:54 AM
That did the trick! I wonder why that is... perhaps 'closed' is a keyword in Chrome or something?

Thanks for your help!closed is a standard property of window. Seemingly Chrome just won't allow its misuse.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum