Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    80
    Thanks
    13
    Thanked 0 Times in 0 Posts

    [SOLVED] Variable returns correctly in FF, incorrect in Chrome

    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*
    Last edited by kberry; 12-22-2011 at 09:39 PM. Reason: SOLVED

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,567
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    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.
    Code:
    <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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    kberry (12-22-2011)

  • #3
    New Coder
    Join Date
    Jun 2011
    Posts
    80
    Thanks
    13
    Thanked 0 Times in 0 Posts
    That did the trick! I wonder why that is... perhaps 'closed' is a keyword in Chrome or something?

    Thanks for your help!

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,567
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    Quote Originally Posted by kberry View Post
    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:
    Quote Originally Posted by old pedant;
    I would bet a latte that closed is a keyword in Chrome JavaScript.
    <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by kberry View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •