Jump to content

[SOLVED] Javascript Mouse Off Page


Guest

Recommended Posts

I want to run a function when the mouse if off the page so I made a div that has the whole page in it and the div has a onmouseout function but when I go to mouseover certian things it still does it.

 

This is what I want it like

http://www.market-soft.com/eg/

 

This is what i got going

http://caribongoflorida.com/

 

Can you help me

Link to comment
https://forums.phpfreaks.com/topic/62743-solved-javascript-mouse-off-page/
Share on other sites

Well, I don't know whether your still working on it at the moment, but I cant see anything happening at all on your site.

 

If its of any help to you, the other site you mentioned works by tracking the cursor position rather than onmouseout, when the cursor gets to less than 20px from the top of the window it displays the message window.

Try this:

 

<html>
<head>
<script type='text/javascript'>
var x, y, winWidth, winHeight;
function init() {
  getWinSize();
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onresize = getWinSize;
  document.onmousemove = getXY;
  setInterval('check();', 1);
}
function getWinSize() {
  winWidth = document.body.clientWidth-2;
  winHeight = document.body.clientHeight-2;
}
function getXY(e) {
  x = (window.Event) ? e.pageX : event.clientX;
  y = (window.Event) ? e.pageY : event.clientY;
}
function check() {
  if((x<=1 || x>=winWidth) || (y<=1 || y>=winHeight))
    alert('Off Page');
}
</script>
</head>

<body onload='init();'>
Your web page goes here...<br>
</body>
</html>

 

Hope this helps some.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.