Welcome to WebmasterWorld Guest from 54.221.49.52

Forum Moderators: open

Message Too Old, No Replies

JS ERROR with Windows 7 - 64bits

The code is fine but doesn't work with Win7 - 64bits.

     

explorador

9:07 pm on Oct 11, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi, suddenly one of my scripts began trowing errors but the code is fine. I checked and somehow getting the date object and data doesn't work with ANY of my browser under WIN7 64. Opera, IE, FF, Safari... none.

I checked the w3schools example and the one with milliseconds gets 0 as a result. Any ideas on how to get around this?

[w3schools.com...]


I tested my app under every browser on Windows and several browsers under Ubuntu Linux, no problem, only with Windows7 64 bits.... weird...

explorador

9:11 pm on Oct 11, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Forgot to add: I searched the web but I don't seem to find others with the problem. Could it be anything else that only applies to me in this case? double checked, no idea.

explorador

10:23 pm on Oct 11, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



For get what I wrote, the code is fine, but the short way is not working, the long way it is (win7 x64), on the rest of systems doesn't need modifications. Not solved but... solved!

penders

10:50 pm on Oct 11, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Just to clarify, are using saying the following returns 0 under Win7 64bit?

var d = new Date(); 
document.writeln(d.getMilliseconds());


...and the long way uses getTime()?

explorador

11:21 pm on Oct 11, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Just to clarify, are using saying the following returns 0 under Win7 64bit?


The following page "try it" gives me 0 every time, unless that's what is supposed to result... </clueless>

[w3schools.com...]


The code has been working fine with every browser, but now at work have a new machine with Win7 x64, and this is the first time I'm getting this error.

In the function I was generating a 13 digit number using the hour, minutes, seconds, etc using one line ++++, now I used one var for each part of the long digit and then joined them, now it works. Very strange. Sorry for the confusion.

penders

12:58 am on Oct 12, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



The following page "try it" gives me 0 every time, unless that's what is supposed to result...


Yes, that is the expected result in that particular example since the time portion of the string does not specify the number of milliseconds. It returns 0 in the same way that getSeconds() also returns 0.

However, my code example above (which is actually Example#1 from the w3schools page you link to) should give a result in the range 0-999. The w3schools example on that page is a live example, so refreshing the page a few times should give different results.

I don't have access to Win7 64bit, but I would guess it was something else that is breaking!? :) With a 64bit OS it is quite possible you could get different results from floating-point arithmetic expressions due to the increased precision - although I'm not sure how that would come into play here.

I would be interested to see the code which you say isn't working.

Btw, getTime() returns the internal representation of the Date object in milliseconds, which is currently a 13 digit number.

explorador

2:14 pm on Oct 12, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Thanks penders for the correction.
I would be interested to see the code which you say isn't working.

I was getting the numbers and adding them one to another in one line, it was working, but suddenly instead of forming a long string they began to sum into one number (as numbers not as strings). I thought about the milliseconds becase when I started removing parts of the line, removing that one seemed to work. The code was fixed, since I removed that part in the first place I'm not sure anymore, perhaps it was something that was modified along the way on my multireplacements (working with several scripts at once on my editor).

Thanks, I was worried about it.

penders

7:08 pm on Oct 12, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



I was getting the numbers and adding them one to another in one line, it was working, but suddenly instead of forming a long string they began to sum into one number (as numbers not as strings).


I was wondering if this might have been happening - it can be the cause of many a problem. If all parts of the expression are numbers then '+' should numerically add them all together. However, since '+' is also the string concatenation operator, then JavaScript determines at runtime, depending on the data types of the operands exactly what to do. And this can sometimes give unexpected results.

However, why this should behave differently on Win7 64bit is still a bit of a mystery, other than the fact that a 64bit OS will have a far greater numeric range before the numbers overflow. On a 32bit OS the numbers might result in overflow and so JS resorts to string concatenation - but that is a wild guess!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month