Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!e) var e = window.event; // Internet Explorer
- if (!e) e = window.event; // Internet Explorer
- <html>
- <head>
- <title>Mouse Coordinates</title>
- <script type="text/javascript">
- function getCoords(e) {
- var x = 0; // x and y positions
- var y = 0;
- if (!e) var e = window.event; // Internet Explorer
- if (e.pageX || e.pageY) { // Firefox
- x = e.pageX;
- y = e.pageY;
- }
- else if (e.clientX || e.clientY) {
- x = e.clientX + document.body.scrollLeft
- + document.documentElement.scrollLeft;
- y = e.clientY + document.body.scrollTop
- + document.documentElement.scrollTop;
- }
- // x and y contain the mouse position
- // relative to the document
- alert(x + ", " + y);
- }
- </script>
- </head>
- <body>
- <div style="background-color: aqua; position: absolute; top: 50px"
- onmouseover="return getCoords(event);">
- <h1>Mouse positions are relative to the document, not the
- <div> container</h1>
- </div>
- </body>
- </html>
- function getCoords(e) {
- e = e || window.event;
- ...
- }
- x = 12; // using the variable "before" it is declared works
- var x = x + 1;
Add Comment
Please, Sign In to add comment