| | |
javascript in mozilla firefox
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
They are properties of the Event Object. From the www.w3.org:
So "event.clientX' should work, depending on how you are getting the "Event" object.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
// 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.
•
•
Join Date: Jan 2006
Posts: 2
Reputation:
Solved Threads: 0
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 .....
Regards,
Ramesh
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 .....
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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 10:08 am. Reason: Added code tags
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
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:
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:
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:
This will work to create an alert when the user closes the window:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- 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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- 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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- 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>
•
•
Join Date: Mar 2006
Posts: 6
Reputation:
Solved Threads: 0
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- 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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- 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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- 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>
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.
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.
![]() |
Similar Threads
- session varibale is running in IE but not in mozilla firefox (PHP)
- Problem with javascript code in Mozilla firefox. (JavaScript / DHTML / AJAX)
- How to correct this javascript UNDER Mozilla Firefox? (JavaScript / DHTML / AJAX)
- mozilla firefox 0.8 (Windows NT / 2000 / XP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Calculating Price in JavaScript
- Next Thread: javascript to load images?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp animate array automatically beta box bug calendar cart checkbox class codes column createrange() css cursor date debugger decimal design dom download dropdown editor element embed enter error explorer firefox focus frameworks getselection google gwt hint html htmlform ie7 ie8 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseover onreadystatechange parent paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search select shopping size sql text textarea toggle w3c web website window windowofwords windowsxp wysiwyg \n






