3

I have narrowed down my error to following set of codes producing different behaviour in google Chrome:

Sample Code: http://jnvxxx.appspot.com/rpc/static_server?key_=testjs.html

Firefox Output:Hi 1 [object Object]192 Hi 2

Chrome Output: Hi 1 [object Object]undefined Hi 2

Any idea hot to get attributes working in google chrome as well.

Thanks.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539

1 Answers1

5

You are accessing the window.status property, which is used to control the text in the status bar. See: http://www.w3schools.com/jsref/prop_win_status.asp.

Apparently, this functionality has to be turned on first in all major browsers, so apparently different browsers do different things when it's turned off. Chrome changes the value of the status property to a string, so it becomes the cryptic-but-familiar string "[object Object]", which has no entry_count property. Firefox leaves the object intact in the status property.

Bottom line: window.status is already being used for something else; use a different name for your variable.

EDIT:

As mentioned below, an even better way do do all this would be to encapsulate it in function scope, as long as you're not going to use it in other places anyway:

(function() {
   var myStatus = {...};
   // Do something with myStatus, preferably not document.write ;)
}());

var a = typeof myStatus; // a === 'undefined'.

This way, the variable will only be visible within the function scope.

Spiny Norman
  • 8,277
  • 1
  • 30
  • 55
  • Thanks Speny... I am amazed :) Working now : Sample: http://jnvxxx.appspot.com/rpc/static_server?key_=testjs2.html – Ram Shanker Jan 08 '11 at 09:15
  • 1
    +1 Good knowledge, sir! As an additional note, this is what happens when you use global variables. Rather than just using a different variable name, it would be a good solution to add a new scope, even if that's just a self-executing anonymous function. – lonesomeday Jan 08 '11 at 10:58
  • @lonesomeday Right you are! I added it as a bonus. – Spiny Norman Jan 08 '11 at 11:50