Jump to content

[SOLVED] Javascript Mouse Off Page


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.