{"id":387,"date":"2006-10-29T08:53:29","date_gmt":"2006-10-29T15:53:29","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/2006\/10\/29\/another-reason-why-i-hate-ie-getting-mouse-coordinates\/"},"modified":"2006-10-29T08:53:29","modified_gmt":"2006-10-29T15:53:29","slug":"another-reason-why-i-hate-ie-getting-mouse-coordinates","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/another-reason-why-i-hate-ie-getting-mouse-coordinates\/","title":{"rendered":"Another Reason why I hate IE &#8211; Getting Mouse Coordinates"},"content":{"rendered":"<p>Fucking IE!!!<\/p>\n<p>If I had a dollar for everytime I say that.<\/p>\n<p>In anycase, I just fixed a bug which has been keeping all the people that visit wedoit4you.com from recommending articles by mail to their friends.<\/p>\n<p>It has to do with getting the current position of the mouse.<\/p>\n<p>Every other browser implementation considers the mouse position relative to the beginning of the the document, stupid microsoft developers were too lazy to add up the amount of scroll, and they not only were too lazy to do it like everyone else, their <b>document.body.scrollTop<\/b> function always returns 0, it turns out that you have to do <b>document.documentElement.scrollTop<\/b> to get the stupid scrollTop variable.<\/p>\n<p>Yet another reason to hate IE&#8217;s guts even more.<\/p>\n<p>So, kids, if you need a function that gives you the correct mouse position, relative to the beginning of your document, no matter how much you scrolldown, here it is:<\/p>\n<p><code><br \/>\nvar IE = document.all?true:false<\/p>\n<p>\/\/ If NS -- that is, !IE -- then set up for mouse capture<br \/>\nif (!IE) document.captureEvents(Event.MOUSEMOVE)<\/p>\n<p>\/\/ Set-up to use getMouseXY function onMouseMove<br \/>\ndocument.onmousemove = getMouseXY;<\/p>\n<p>\/\/ Temporary variables to hold mouse x-y pos.s<br \/>\nvar tempX = 0<br \/>\nvar tempY = 0<\/p>\n<p>\/\/ Main function to retrieve mouse x-y pos.s<\/p>\n<p>function getMouseXY(e) {<br \/>\n  if (IE) { \/\/ grab the x-y pos.s if browser is IE<br \/>\n    tempX = event.clientX + document.documentElement.scrollLeft<br \/>\n    tempY = event.clientY + document.documentElement.scrollTop<br \/>\n    \/\/FUCKING IE, not only it considers mouse position<br \/>\n    \/\/relative to the current view, but it didn't retrieve<br \/>\n    \/\/the scroll value with document.body.scrollTop... MOTHERFUCKERS<br \/>\n  } else {  \/\/ grab the x-y pos.s if browser is NS<br \/>\n    tempX = e.pageX<br \/>\n    tempY = e.pageY<br \/>\n  }<br \/>\n  \/\/ catch possible negative values in NS4<br \/>\n  if (tempX < 0){tempX = 0}\n  if (tempY < 0){tempY = 0}\n  \/\/ show the position values in the form named Show\n  \/\/ in the text fields named MouseX and MouseY\n\n  return true\n}\n<\/code><\/p>\n<p>Put that on one of the javascripts that you load, probably the first one actually, since the idea is to use global variables \"tempX\" and \"tempY\" to get the current mouse position at all times.<\/p>\n<p><a href=\"http:\/\/www.evolt.org\/article\/Mission_Impossible_mouse_position\/17\/23335\/index.html\">I learned about all this thanks to this post<\/a> from Stephen Chapman.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fucking IE!!! If I had a dollar for everytime I say that. In anycase, I just fixed a bug which has been keeping all the people that visit wedoit4you.com from recommending articles by mail to their friends. It has to do with getting the current position of the mouse. Every other browser implementation considers the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[30],"tags":[],"class_list":["post-387","post","type-post","status-publish","format-standard","hentry","category-geeklife"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-6f","jetpack-related-posts":[{"id":3078,"url":"https:\/\/www.gubatron.com\/blog\/how-to-obtain-the-coordinates-of-the-jtable-cell-a-mouse-is-hovering-over-useful-for-tooltips-within-cell-renderers\/","url_meta":{"origin":387,"position":0},"title":"How to obtain the coordinates of the JTable cell a mouse is hovering over, useful for tooltips within cell renderers.","author":"gubatron","date":"June 19, 2013","format":false,"excerpt":"public String getToolTipText(MouseEvent event) { \/* * This is a Java Swing lesson on how to obtain the coordinates of the current cell * as you hover with the mouse on a JTable. * * You cannot use the renderer component, since it seems that once the table is done\u2026","rel":"","context":"In \"cell rectangles\"","block_context":{"text":"cell rectangles","link":"https:\/\/www.gubatron.com\/blog\/tag\/cell-rectangles\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":355,"url":"https:\/\/www.gubatron.com\/blog\/gotcha\/","url_meta":{"origin":387,"position":1},"title":"Gotcha!","author":"gubatron","date":"August 4, 2006","format":false,"excerpt":"Gotcha! Originally uploaded by Gubatron. Finally got the damn little mouse that we had as an unwanted guest in the apartment. There were two, finally got them both today with this trap we got at the 99 cent store.","rel":"","context":"In &quot;Geeklife&quot;","block_context":{"text":"Geeklife","link":"https:\/\/www.gubatron.com\/blog\/category\/geeklife\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":40,"url":"https:\/\/www.gubatron.com\/blog\/stomp-moma-y-rockefeller-center-ice-skating\/","url_meta":{"origin":387,"position":2},"title":"Stomp, MOMA y Rockefeller Center ICE Skating","author":"gubatron","date":"November 22, 2004","format":false,"excerpt":"Me pusieron Internet!! a 2.5 mbps no tan r\u00e1pido como antes -3.4mbps-, pero full chola de todos modos, por eso este mont\u00f3n de updates al blog, todos atrasados, y uno detr\u00e1s del otro. Este fin empez\u00f3 ayer super bien, lleg\u00f3 una amiga de la universidad que vive ahora en Pto.\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":341,"url":"https:\/\/www.gubatron.com\/blog\/floatcenter\/","url_meta":{"origin":387,"position":3},"title":"float:center","author":"gubatron","date":"July 12, 2006","format":false,"excerpt":"You wish... So many work arounds to center divs, that I was almost getting to the point where I was about to start selling black t-shirts with the words float:center If you're a web developer, web designer, and you have to deal with CSS, and CSS not working properly on\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":903,"url":"https:\/\/www.gubatron.com\/blog\/apple-wireless-keyboard\/","url_meta":{"origin":387,"position":4},"title":"Apple Wireless Keyboard","author":"gubatron","date":"October 23, 2008","format":false,"excerpt":"I just got a new Apple Wireless Keyboad. My laptop currently sits atop a Griffin Elevator, this keeps it cool and also helps keep my neck at a healthy angle, something I need given how many hours I spend on the computer. The problem with the Elevator is that after\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":199,"url":"https:\/\/www.gubatron.com\/blog\/como-en-los-viejos-tiempos\/","url_meta":{"origin":387,"position":5},"title":"Como en los viejos tiempos.","author":"gubatron","date":"September 21, 2005","format":false,"excerpt":"Pues no estoy vendiendo limonada de los limones que me han caido del cielo ultimamente, pero al menos me estoy tomando uno que otro vaso. Dada la indeterminacion de mi estadia en casa, no estoy saliendo mucho, y tengo montado de nuevo mi viejo laboratorio en el lugar que solia\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=387"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/387\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}