jquery - Reload Page or iFrame if user is idle -


this first post here on stackoverflow... understand, cannot re-post questions have been answered, since related answers did not seem work me i'll ask question in more specific details meet requirement:

i trying refresh page or iframe (either good) once user has been idle specific period of time. i'd identify if mouse on actual iframe (without movement) state still considered active. if i'm in different tab of browser , mouse moving or idle, i'd tab contains iframe still refresh.

i have tried use multiple jquery plugins , other solutions yet of them seem not recognize when mouse on iframe, should not refresh.

i've started following code related answer (https://stackoverflow.com/a/4644315)

i'm using vimeo.com example source of iframe.

<html>   <head> <title>iframe autorefresh on idle</title>     <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>  <script>  var time = new date().gettime();  $(document.getelementbyid("iframe1")).bind("mouseover", function(e) {      time = new date().gettime();  });   function refresh() {      if(new date().gettime() - time >= 6000)           window.location.reload(true);      else           settimeout(refresh, 10000);  }   settimeout(refresh, 10000);  </script>  <style>  body {    margin: 0;     }  </style>  </head>  <body>     <iframe id="iframe1" src="http://www.vimeo.com/" style="border: 0; width: 100%; height: 100%">your browser doesn't support iframes.</iframe>  </iframe>  </body>  </html> 

thanks in advance!

if know exact position of iframe on page, can record mouse movement coordinates, if match video located disable refresh.

http://docs.jquery.com/tutorials:mouse_position

edit, maybe.

<!doctype html> <html> <head> <title></title> <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>  <script> $(document).ready(function() {  var timer; function start() {     timer = setinterval(function(){refresh()}, 5000); }  start();  $(document).mousemove(function(e) {      if (e.pagex >= x && e.pagex <= y ) {         //stop if coordinates correct on x intercept         cleartimeout(timer);     } else if (e.pagey >= y && e.pagey <= y ) {         //stop if coordinates correct on y intercept         cleartimeout(timer);     } else {         // not hovering anymore, start counting seconds again...         start();     }  });    function refresh() {     //window.location.reload(true);     alert("refresh!!!"); }  });  </script>   <body>     <iframe id="iframe1" src="http://www.vimeo.com/" style="border: 0; width: 100%; height: 100%">your browser doesn't support iframes.</iframe>  </iframe>   </body>  </html> 

y , x values (in pixels have figure out because have no idea correct coordinates.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -