Skip to main content

Bug Tracker

Side navigation

#6524 closed bug (invalid)

Opened May 04, 2010 02:38PM UTC

Closed July 25, 2010 08:07PM UTC

Last modified March 13, 2012 09:22PM UTC

ie8 and NaNpx value

Reported by: virgil.balibanu Owned by:
Priority: Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:
Description

sometimes it might happen that jquery receives a NaNpx value for a style, like top or left, and ie8 does not like that so it will raise a js error (Invalid Argument) on line 4618 (1.4.2 development version) style[ name ] = value;

this could easily be fixed by either modifying the value to 0px by doing something like this value=(value=='NaNpx'?'0px':value); or by putting the assignment in a try catch block. Could you please do either of this, because it's very hard for the user to find where the NaNpx will appear from.

Attachments (0)
Change History (9)

Changed May 05, 2010 02:14AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

If your code is passing "NaNpx" to jQuery then it is passing in invalid arguments. You can easily tell which code is to blame by using the IE8 debugger (Press F12) and view the call stack at the point of the error.

Changed May 05, 2010 07:50AM UTC by virgil.balibanu comment:2

resolution: invalid
status: closedreopened

well, only ie8 sees NaNpx as an error, ie7 and ff ignore it. And second I have my windows on a virtual machine so that I can test my site with ie, so the debugger is pretty useless. I had to download the jquery development version and print elem.id in a catch block to see where the exception was coming from.

The error comes from jquery, as in a few methods in js i gave dimensions ending in 'px', like this:

var top = document.documentElement.clientHeight + document.documentElement.scrollTop + 'px';

$('#wrraper_help_window').css({'top': top});

So i presume it is a jquery bug. Probably trying to parse the value as an integer directly and returning NaN then adding 'px' to it.

Changed May 05, 2010 11:55PM UTC by dmethvin comment:3

resolution: → invalid
status: reopenedclosed

I don't see any use of

document.documentElement.scrollTop
in jQuery itself. If you can provide a complete test case that demonstrates that the problem is internal to jQuery (that is, the
"NaNpx"
is coming from within jQuery and not your code) then attach the test case and reopen the ticket.

Changed May 26, 2010 12:15AM UTC by marcdraco comment:4

resolution: invalid
status: closedreopened

I may be wrong here, but I have had a similar issue.

here is a snippet where the "target" is from the event object. I seemed to be getting NaNs from ParseINT which seems to suggest that IE is pulling a fast one on jQuery. The solution for me is to test for the NaN and 0 the value.

cssOffset.X = parseInt($(target).css("margin-left"),10);

cssOffset.Y = parseInt($(target).css("margin-top"),10);

cssOffset.X = (isNaN(cssOffset.X)) ? 0 : cssOffset.X;

cssOffset.Y = (isNaN(cssOffset.Y)) ? 0 : cssOffset.Y;

It appears that IE8 returns "auto" for these values unless they are explicitly set - whereas (FF) presumably returns the computed style.

Changed May 27, 2010 01:33AM UTC by dmethvin comment:5

resolution: → invalid
status: reopenedclosed

No test case attached. Please do not reopen this ticket without a test case.

Changed June 25, 2010 04:54AM UTC by readyman comment:6

Although this is probably not jquery's fault, there is no error handling in the offending line & all the debuggers I have used point to a line in the jquery code and not to any plugin scripts. I would have to basically rewrite the plugins to make this error go away. Not a good solution.

Here is the quick fix...

Find the "offending" code in jquery code around line 4618

style[ name ] = value;

replace with

try{style[ name ] = value;} catch (error){};

If using the minified version

Around line 116 change

f[b]=d;

to

try{f[b]=d;}catch (error){};

Changed July 20, 2010 09:46PM UTC by cmcculloh comment:7

resolution: invalid
status: closedreopened

I believe this is actually a result of passing an object with only one property to the offset function:

Steps to reproduce:

Run this code in IE 7 with script debugging ENABLED:

<!DOCTYPE html>

<html>

<head>

<style>p { margin-left:10px; } </style>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

</head>

<body>

<p>Hello</p><p>2nd Paragraph</p>

<script>$("p:last").offset({ top: 10 });</script>

</body>

</html>

Note that we only passed { top: 10 } to offset instead of { top: 10, left: 10 }.

Expected Result:

2nd paragraph moved to top 10px with no errors

Actual Result:

2nd paragraph moved to top 10px with "Invalid Argument" runtime errors being thrown

The problem is actually line 4618 of the un-minified jquery source 1.4.2:

style[ name ] = value;

"value" here is set to "NaNpx", which, while technically correct is sub-optimal. It seems there should be some error checking added:

if(value !== "NaN" && value !== "NaNpx"){

style[ name ] = value;

}

(or something more optimal, idk, this is my first bug ticket...)

Forking project, submitting patch: http://github.com/cmcculloh/jquery/commit/2bbffc5f84dfabfd45f80069838d42a3b4e6034e

Changed July 21, 2010 01:47AM UTC by cmcculloh comment:8

Looks like this was already fixed in a much better way in commit 08cf82e88e7a1f88da34 by brandonaaron on 3/22/2010.

Changed July 25, 2010 08:07PM UTC by dmethvin comment:9

resolution: → invalid
status: reopenedclosed

Since we're lacking a test case lets just say that this was fixed by the 3/22 patch and it will be fixed in the next release. Since there's no test case it's not possible to know if it will really be fixed. If someone can come up with a test case that shows the patch fixed the problem I'll change the status of this bug to "fixed".