User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 330,161 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,154 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 29062 | Replies: 9
Reply
Join Date: Dec 2004
Location: Ph
Posts: 27
Reputation: odee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
odee odee is offline Offline
Light Poster

javascript in mozilla firefox

  #1  
Jan 3rd, 2005
why does the event.clientX and event.clientY is working in IE but not work in firefox?

clientX and clientY shows the coordinate of the cursor relative to the screen
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 33
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: javascript in mozilla firefox

  #2  
Jan 3rd, 2005
Because the event object model is different in FireFox. Instead of using the IE Dom, you need to use the W3C Dom.

Let me know if you need more specific help.
Reply With Quote  
Join Date: Jan 2006
Posts: 2
Reputation: ramesh_karanam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ramesh_karanam ramesh_karanam is offline Offline
Newbie Poster

Re: javascript in mozilla firefox

  #3  
Jan 18th, 2006
So how to know the equivalent values in firefox ....

I'm having a requirement where I need to get the co-ordinates.
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 33
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: javascript in mozilla firefox

  #4  
Jan 18th, 2006
They are properties of the Event Object. From the www.w3.org:

// Introduced in DOM Level 2:
interface MouseEvent : UIEvent {
  readonly attribute long             screenX;
  readonly attribute long             screenY;
  readonly attribute long             clientX;
  readonly attribute long             clientY;
  readonly attribute boolean          ctrlKey;
  readonly attribute boolean          shiftKey;
  readonly attribute boolean          altKey;
  readonly attribute boolean          metaKey;
  readonly attribute unsigned short   button;
  readonly attribute EventTarget      relatedTarget;
  void               initMouseEvent(in DOMString typeArg, 
                                    in boolean canBubbleArg, 
                                    in boolean cancelableArg, 
                                    in views::AbstractView viewArg, 
                                    in long detailArg, 
                                    in long screenXArg, 
                                    in long screenYArg, 
                                    in long clientXArg, 
                                    in long clientYArg, 
                                    in boolean ctrlKeyArg, 
                                    in boolean altKeyArg, 
                                    in boolean shiftKeyArg, 
                                    in boolean metaKeyArg, 
                                    in unsigned short buttonArg, 
                                    in EventTarget relatedTargetArg);
};

So "event.clientX' should work, depending on how you are getting the "Event" object.
Reply With Quote  
Join Date: Jan 2006
Posts: 2
Reputation: ramesh_karanam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ramesh_karanam ramesh_karanam is offline Offline
Newbie Poster

Re: javascript in mozilla firefox

  #5  
Jan 19th, 2006
Thanks for the reply Greer...

But, my requirement is to show a pop-up if on close of the browser window. The below sample script is working well in IE but not in FireFox.

Could you please let me know the solution for Firefox .....

<html><head><title>Test</title> 
<script language ="Javascript"> 
 
function unLoadFnc(event) 
{
 if(window.event.clientX<-2000 && window.event.clientY<-2000)
 {
  alert("Closing the window .. ");
 }
 else
 {
  alert("Something else..");
 }
}
 
</script> 
</head> 
<body onUnload="unLoadFnc(event)"> 
Sample Html. 
</body> 
</html> 

Regards,
Ramesh
Last edited by tgreer : Jan 19th, 2006 at 9:08 am. Reason: Added code tags
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 33
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: javascript in mozilla firefox

  #6  
Jan 19th, 2006
There is quite a bit wrong in your code. First, you absolutely don't need to measure any mouse position or x,y coordinates do what you've asked.

This will work to create an alert when the user closes the window:

<!-- note: you're missing a doctype here! -->
<html>
<head>
<title>Test</title> 
<script type="text/javascript"> 
 
function unLoadFnc() 
{
  alert("Closing the window .. ");
}
 </script> 
</head> 
<body onUnload="unLoadFnc();"> 
Sample Html. 
</body> 
</html> 

There's no need for events, clientX, any of that. Perhaps though, you're not showing me the entire script or explaining the entire project. So, in the case that you DO need the event, you need to test if it's part of the window object (IE) or not.

Here's how I would code it:

<!-- doctype excluded, you need to pick one -->
<html>
<head>
<title>Test</title>

<script type="text/javascript">
function unLoadFnc(evt)
{
  var e = (window.event) ? window.event : evt;
  alert(e.clientX);
}
</script>
</head>

<body onUnload="unLoadFnc(event);">

Sample Html.
</body>
</html>

I hope you're noting a few things, such as the fact that your page needs a doctype declaration, the proper way to write a script tag, and the semicolon after your event handler assignment.

The goal is to pass in the event object, and in your function, create a variable to hold it, using the tertiary operator.

Note, in FireFox, if you ran this code, the alert would say "undefined". That's because the widget that closes the window (the 'X') isn't within the client, so clientX would be undefined.

You'd actually have to click something in the client area to get a value.

For example, a button:

<!-- doctype excluded, you need to pick one -->
<html>
<head>
<title>Test</title>

<script type="text/javascript">
function unLoadFnc(evt)
{
  var e = (window.event) ? window.event : evt;
  alert(e.clientX);
}
</script>
</head>
<body>
Sample Html.
<form>
<input type="button" onclick="unLoadFnc(event);" />
</form>

</body>
</html>
Reply With Quote  
Join Date: Mar 2006
Posts: 6
Reputation: unicorn11 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
unicorn11 unicorn11 is offline Offline
Newbie Poster

Re: javascript in mozilla firefox

  #7  
Apr 10th, 2006
the problem with this page is that the event that you have fired happens even if the page is refreshed. and he does not what that to happen. he wants to call the event only when the browser window is shut

Originally Posted by tgreer
There is quite a bit wrong in your code. First, you absolutely don't need to measure any mouse position or x,y coordinates do what you've asked.

This will work to create an alert when the user closes the window:

<!-- note: you're missing a doctype here! -->
<html>
<head>
<title>Test</title> 
<script type="text/javascript"> 
 
function unLoadFnc() 
{
  alert("Closing the window .. ");
}
 </script> 
</head> 
<body onUnload="unLoadFnc();"> 
Sample Html. 
</body> 
</html> 

There's no need for events, clientX, any of that. Perhaps though, you're not showing me the entire script or explaining the entire project. So, in the case that you DO need the event, you need to test if it's part of the window object (IE) or not.

Here's how I would code it:

<!-- doctype excluded, you need to pick one -->
<html>
<head>
<title>Test</title>

<script type="text/javascript">
function unLoadFnc(evt)
{
  var e = (window.event) ? window.event : evt;
  alert(e.clientX);
}
</script>
</head>

<body onUnload="unLoadFnc(event);">

Sample Html.
</body>
</html>

I hope you're noting a few things, such as the fact that your page needs a doctype declaration, the proper way to write a script tag, and the semicolon after your event handler assignment.

The goal is to pass in the event object, and in your function, create a variable to hold it, using the tertiary operator.

Note, in FireFox, if you ran this code, the alert would say "undefined". That's because the widget that closes the window (the 'X') isn't within the client, so clientX would be undefined.

You'd actually have to click something in the client area to get a value.

For example, a button:

<!-- doctype excluded, you need to pick one -->
<html>
<head>
<title>Test</title>

<script type="text/javascript">
function unLoadFnc(evt)
{
  var e = (window.event) ? window.event : evt;
  alert(e.clientX);
}
</script>
</head>
<body>
Sample Html.
<form>
<input type="button" onclick="unLoadFnc(event);" />
</form>

</body>
</html>
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: javascript in mozilla firefox

  #8  
Apr 10th, 2006
Tgreer had more than one example.. if you read his comments and code you will learn much about event handling in mozilla.

To copy and paste, try the last example. to get the x and y coordinates, look at where tgreer posted the event object properties.

cheers.
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: javascript in mozilla firefox

  #9  
Apr 10th, 2006
wow, this thread is old...
Reply With Quote  
Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 33
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: javascript in mozilla firefox

  #10  
Apr 10th, 2006
Yeah... I wondered how/why it got bumped. No big deal.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:14 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC