942,956 Members | Top Members by Rank

Ad:
Aug 15th, 2010
0

event works in IE but not in firefox

Expand Post »
Can you help me with the equivalent code of this in firefox?
Thanks in advance.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Event Handling</title>
  4. <script type="text/javascript">
  5. <!--
  6. //MOUSE COORDINATES
  7. function updateMouseCoordinates(){
  8. coordinates.innerText = event.srcElement.tagName + "(" + event.offsetX + "," + event.offsetY + ")";//works on IE not in firefox
  9. }
  10. //-->
  11. </script>
  12. </head>
  13. <body onmousemove="updateMouseCoordinates()">
  14. <span id="coordinates">(0,0)</span>
  15.  
  16. </body>
  17. </html>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
aladar04 is offline Offline
37 posts
since Sep 2009
Aug 15th, 2010
0
Re: event works in IE but not in firefox
Try mousemove instead of onmousemove.
Sponsor
Featured Poster
Reputation Points: 546
Solved Threads: 716
Bite my shiny metal ass!
pritaeas is offline Offline
4,142 posts
since Jul 2006
Aug 15th, 2010
0
Re: event works in IE but not in firefox
I don't know why this works in IE, but I know why it doesn't in Firefox. coordinates.innerHTML won't work because coordinates is not a valid object (in Firefox). Instead, use: document.getElementById('coordinates').innerHTML = [...].
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iPeterS is offline Offline
3 posts
since Aug 2010
Aug 15th, 2010
0
Re: event works in IE but not in firefox
Required modifications:
- The innerText property is not supported by Firefox (the textContent property provides similar functionality in Firefox). In that case, the innerHTML property can also be used.
- The event.srcElement property is not supported by Firefox, use the target and srcElement properties together.
- The event.offsetX property is not supported by Firefox, use the cross-browser clientX property instead.
- The window.event property is not supported in Firefox. In Firefox, when an event occurs, an instance of the event object is initialized and passed to the event handlers as the first parameter.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <head>
  2. <title>Event Handling</title>
  3. <script type="text/javascript">
  4. function updateMouseCoordinates (event) {
  5. var target = event.target ? event.target : event.srcElement;
  6.  
  7. var coordinates = document.getElementById ("coordinates");
  8. coordinates.innerHTML = target.tagName + "(" + event.clientX + "," + event.clientY + ")";
  9. }
  10. </script>
  11. </head>
  12. <body onmousemove="updateMouseCoordinates(event)">
  13. <span id="coordinates">(0,0)</span>
  14. </body>

I think, the following links will be useful to you:
event object (event handling),
textContent property,
innerText property,
innerHTML property,
target property,
srcElement property,
clientX property,
clientY property.
Last edited by gumape; Aug 15th, 2010 at 11:06 am.
Reputation Points: 13
Solved Threads: 2
Newbie Poster
gumape is offline Offline
16 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Get acces to a Radio Button
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: passing querystrings working partially





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC