Jump to content

[SOLVED] Javascript Mouse Off Page


Guest

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.