Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Try this:
    Code:
    <iframe src="rqserver.exe" onload="detectIdle(this.contentWindow);"></iframe>
    Then replace these lines:
    Code:
    document.onmousemove=initRedirect;
    document.onclick=initRedirect;
    document.onkeydown=initRedirect;
    window.onload=initRedirect;
    window.onresize=initRedirect;
    with this function:
    Code:
    function detectIdle(win){
      if (!win) win = window;
      win.document.onmousemove=initRedirect;
      win.document.onclick=initRedirect;
      win.document.onkeydown=initRedirect;
      win.onresize=initRedirect;
    }
    This will detect idle on the iframe but not on the main page.

  2. Users who have thanked glenngv for this post:

    froglander (04-03-2008)

  3. #17
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Your answers are great! How did you learn so much?

    Got things mostly working with your last suggestions only to discover that some of the pages that are returned by that rqserver.exe file contain frames. Only like, 2 or 3 of them. (There are a number of pages generated by that cgi file). So, my question is, do you know of a way for the idle detect to work on a frame inside an iframe?

    Thanks so much!

    (One of my bosses is originally from the Philippines too, as I see it says you are, I think that's neat )

  4. #18
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    This will idle detect in each iframe and all its sub-iframes and sub-frames up to the innermost frame/iframe, if any.

    Change the detectIdle function with the below function and add the setWinHandlers and xAttachEvent functions. I made a cross-browser event registration that will not override the events set in these codes if those are already registered inside the frames/iframes.
    Code:
    function detectIdle(win){
      if (!win) win = window;
      setWinHandlers(win);
    
      //idle detect for each iframe inside each iframe
      var iframes = win.document.getElementsByTagName('iframe');
      for (var i=0; i<iframes.length; i++){
        win = iframes[i].contentWindow;
        setWinHandlers(win);
        detectIdle(win);
      }
    
      //idle detect for each frame inside each frameset
      var frames = win.frames;
      for (var i=0; i<frames.length; i++){
        win = frames[i];
        setWinHandlers(win);
        detectIdle(win);
      }
    }
    
    function setWinHandlers(win){
      xAttachEvent(win.document, 'mousemove', initRedirect);
      xAttachEvent(win.document, 'click', initRedirect);
      xAttachEvent(win.document, 'keydown', initRedirect);
      xAttachEvent(win, 'resize', initRedirect);
    }
    
    function xAttachEvent(el, evtName, handler){
      if (el.addEventListener){
         el.addEventListener(evtName, handler, false);
      }
      else if (el.attachEvent){
        el.attachEvent('on' + evtName, handler);
      }
    }
    (Tell your boss, "Kumusta ka na?" )

  5. Users who have thanked glenngv for this post:

    froglander (04-10-2008)

  6. #19
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I feel bad asking so many questions! But I replaced the previous detectIdle(win) function with the new one you posted here, as well as adding the other two functions and it still is not detecting mouse movement when there are frames involved in the document that is inside the iframe. If there are no frames it works perfectly. But if there are frames I can only get the timer to reset if I move the scrollbar or let the mouse hover a moment over the division between frames. I've read through your code but I am not even quite sure how to go about troubleshooting it. Thanks again so much for your help!

    --------From my boss---------
    He says "mabuti" and "Taga saan ka sa Pinas?"

  7. #20
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    You mean when you move your mouse over the document inside the frames, the timer is not reset? And it only works when you move the scrollbars and mouse over the frame border? How about when you click on the document, hit any key while on the document and resize the frame? What browser are you using? I tried it in Firefox 2 and IE7 and it works.


    (To your boss..."Taga Batangas, ikaw?")

  8. #21
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ok, in Firefox I tried resizing, clicking, typing and moving the mouse. Resizing would reset the timer but none of the others would.

    In IE7, not even resizing worked to reset the timer.


    (Hopefully I am including the code from the .js file correctly in this post)
    Code:
    /*This javascript file is from glennv elite coder of www.codingforums.com*/
    
    /**********************************************************/
    /* This function sets and clears timers in the detection  */
    /* of mouse activity.									  */
    /**********************************************************/
    var xScroll, yScroll, timerPoll, timerRedirect, timerClock;
    
    function initRedirect(){
      if (typeof document.body.scrollTop != "undefined"){ //IE,NS7,Moz
        xScroll = document.body.scrollLeft;
        yScroll = document.body.scrollTop;
    
        clearInterval(timerPoll); //stop polling scroll move
        clearInterval(timerRedirect); //stop timed redirect
        
        timerPoll = setInterval("pollActivity()",1); //poll scrolling
        timerRedirect = setInterval("showWarning()",10000); //set timed redirect
    
        //for tracking only
        clearInterval(timerClock);
        document.getElementById("clock").innerHTML="0";
        timerClock=setInterval("document.getElementById('clock').innerHTML=parseInt(document.getElementById('clock').innerHTML,10)+1",1000);
        //end tracking
      }
      else if (typeof window.pageYOffset != "undefined"){ //other browsers that support pageYOffset/pageXOffset instead
        xScroll = window.pageXOffset;
        yScroll = window.pageYOffset;
    
        clearInterval(timerPoll); //stop polling scroll move
        clearInterval(timerRedirect); //stop timed redirect
    
        timerPoll = setInterval("pollActivity()",1); //poll scrolling
        timerRedirect = setInterval("showWarning()",10000); //set timed redirect
    
        //for tracking only
        clearInterval(timerClock);
        document.getElementById("clock").innerHTML="0";
        timerClock=setInterval("document.getElementById('clock').innerHTML=parseInt(document.getElementById('clock').innerHTML,10)+1",1000);
        //end tracking
      }
      //else do nothing
    }
    
    /**********************************************************/
    /* This function checks for activity on the screen.	  	  */
    /**********************************************************/
    function pollActivity()
    {
    	if ((typeof document.body.scrollTop != "undefined" && (xScroll!=document.body.scrollLeft || 
    		 yScroll!=document.body.scrollTop)) //IE/NS7/Moz
      	  	 ||
       	   	(typeof window.pageYOffset != "undefined" && (xScroll!=window.pageXOffset || yScroll!=window.pageYOffset))) //other browsers
    	{
    		initRedirect(); //reset polling scroll position
      	}
    }
    
    /**********************************************************/
    /* This will idle detect in each iframe and all its 	  */
    /* sub-iframes and sub-frames up to the innermost 		  */
    /* frame/iframe, if any 								  */
    /**********************************************************/
    function detectIdle(win){
      if (!win) win = window;
      setWinHandlers(win);
    
      //idle detect for each iframe inside each iframe
      var iframes = win.document.getElementsByTagName('iframe');
      for (var i=0; i<iframes.length; i++){
        win = iframes[i].contentWindow;
        setWinHandlers(win);
        detectIdle(win);
      }
    
      //idle detect for each frame inside each frameset
      var frames = win.frames;
      for (var i=0; i<frames.length; i++){  
        win = frames[i];
        setWinHandlers(win);
        detectIdle(win);
      }
    }
    
    function setWinHandlers(win){
      xAttachEvent(win.document, 'mousemove', initRedirect);
      xAttachEvent(win.document, 'click', initRedirect);
      xAttachEvent(win.document, 'keydown', initRedirect);
      xAttachEvent(win, 'resize', initRedirect);
    }
    
    function xAttachEvent(el, evtName, handler){
      if (el.addEventListener){
         el.addEventListener(evtName, handler, false);
      }
      else if (el.attachEvent){
        el.attachEvent('on' + evtName, handler);
      }
    }
    
    /**********************************************************/
    /* This function shows the warning by calling toggleLayer */
    /* and setting a timer to redirect to the lougout page.   */
    /**********************************************************/
    function showWarning()
    {
    	
    	toggleLayer('mysvcwarning');
    	clearInterval(timerRedirect); //stop timed redirect
    	timerRedirect = setInterval("location.href='https://secure.skagit.edu/login/logout.asp'",20000); //set timed redirect
    
    
    }
    /**********************************************************/
    /* This javascript file I swiped from James (the SVC 	  */
    /* webmaster) to toggle the visibility of a div layer     */
    /**********************************************************/
    function toggleLayer(whichLayer)
    {
    	if (document.getElementById)
    	{
    		// this is the way the standards work
    		var style2 = document.getElementById(whichLayer).style;
    		style2.display = style2.display? "":"block";
    		
    		// this line sets the focus to the link in the warning layer
    		document.getElementById('warning').focus();
    		
    	}
    	else if (document.all)
    	{
    		// this is the way old msie versions work
    		var style2 = document.all[whichLayer].style;
    		style2.display = style2.display? "":"block";
    
    		// this line sets the focus to the link in the warning layer		
    		document.all['warning'].focus();
    
    	}
    	else if (document.layers)
    	{
    		// this is the way nn4 works
    		var style2 = document.layers[whichLayer].style;
    		style2.display = style2.display? "":"block";
    		
    	}	
    }
    And then this is the file that uses the idledetect.js file
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    
    <LINK rel="stylesheet" type="text/css" href="includes/style.css" />
    
    <script src="includes/idledetect.js" type="text/javascript"></script>
    
    </head>
    
    </head>
    
    <body>
    
    Timer: <span id="clock" style="font-weight:bold">0</span>
    
    <!--Container for STSOS pages-->
    	<iframe id="mainFrame" name="mainFrame" width="100&#37;" height="100%" src="default_new.asp"
    			onload="detectIdle(this.contentWindow);" 
    			align="middle" frameborder="0" marginheight="0" marginwidth="0"
    			vspace="0"  hspace="0" style="visibility:visible">	
    	</iframe>
    
    <!-- Warning div layer -->
    <div id="mysvcwarning">
    	<p style="text-align:center; font-family:arial, verdana, sans-serif; font-size:0.75em;">
    	This is a reminder to keep your records secure.<br />
    	<a id="warning" href="/login/logout2.asp" target="_parent" onblur="toggleLayer('mysvcwarning')">
    	Click here to clear your records if you are done,</a>
    	<br />
    	or click on the main window to continue.
    	</p>
    </div>
    	
    </body>
    </html>
    -----From my boss-----
    "Ala eh Kumusta Kabayan sa Quezon ang boss ko"

  9. #22
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    The HTML must be in standards-compliant mode causing document.body.scrollTop to always return 0. document.documentElement must be used instead of document.body when in this mode.

    To solve, change the pollActivity function to this:
    Code:
    function pollActivity(){
      var docBody = (document.compatMode == 'CSS1Compat') ? 'documentElement' : 'body';
      if ((typeof document[docBody].scrollTop != "undefined" && (xScroll!=document[docBody].scrollLeft || yScroll!=document[docBody].scrollTop)) //IE/NS7/Moz
       ||
       (typeof window.pageYOffset != "undefined" && (xScroll!=window.pageXOffset || yScroll!=window.pageYOffset))) { //other browsers
          initRedirect(); //reset polling scroll position
      }
    }

    ("Aba magkalapit probinsya pala kami...Baka pwede ako mag-apply sa inyo? ")

  10. #23
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    And I forgot, you also need to modify the initRedirect function:

    Code:
    function initRedirect(){
      var docBody = (document.compatMode == 'CSS1Compat') ? 'documentElement' : 'body';
      if (typeof document[docBody].scrollTop != "undefined"){ //IE,NS7,Moz
        xScroll = document[docBody].scrollLeft;
        yScroll = document[docBody].scrollTop;
        ...
      }
      ...
    }

  11. Users who have thanked glenngv for this post:

    froglander (04-10-2008)

  12. #24
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    One more issue

    Glenngv, your help has been greatly appreciated. If you are still around and still willing to answer one more question on this, it is almost working (I got side-tracked by other projects and this one was put on hold).

    If you go to https://secure.skagit.edu/idledetect.htm you will see it with the clock ticking at the top (IE7 was awful to try and get the iframe to take up the whole page but I finally got it to work). The problem is when you click on the links where it says "Live chat with SVC:". That splits the window into two frames and works until you have entered your name and subject and then click next. After clicking next typing nor mouse movement in the chat window stops the timer but if you move the mouse to the other part of the window, it will stop the timer.

    Do you have any suggestions?

  13. #25
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to detect idle on each iframe and also on the main page?

    Dear glenngv,

    I have 2 iframes in the main page. How I can detect idle on each iframe and also on the main page together? Could you mock up a complete file so I can test it as I try to modify the previous code you post before but fail to do so. (I am weak in js issue )

    Thanks so much for your help.

    Regards,
    felix


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •