...

View Full Version : Another Re-Direct Question



Dingbat
02-10-2004, 01:56 PM
Hi Guys,

Is this possible.

If a page is opened and no action is taken on the page, but left open for maybe 5 min can it be re-directed to another page BUT if the page has been scrolled inside the 5 min then no action to take place. Maybe the time be reset from the last action on the page.

I hope I have made that clear.:confused:

Regards,

The Dingbat

glenngv
02-11-2004, 06:52 AM
Is the scrolling the only thing you want to be monitored. How about mouse moves, clicks and keypresses?

Dingbat
02-11-2004, 09:59 AM
Yes, all keyboard & mouse moves. Just to reset the time and then redirect

glenngv
02-12-2004, 06:45 AM
Tested in IE6, NS7, Moz1
Redirect time is set to 10 secs only for demo purposes.
Timer display is added for tracking purposes only.

Dingbat
02-19-2004, 07:53 PM
Hi Glenn,

I have downloaded the script and it works great except for one small problem.

In the script you have created an eliment id name clock and in the body a span item that calls the clock id. I have tried everything to remove that id but have failed. Can you please direct me to the correct amendment.

Regards,

The Dingbat

Willy Duitt
02-19-2004, 08:17 PM
I'm not Glenn but that is easy to change. :D

Change both instances of this:

//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

With this:

//for tracking only
clearInterval(timerClock);
clock = 0;
timerClock=setInterval("(clock+1)",1000);
//end tracking

And remove the span. ;)

.....Willy

glenngv
02-20-2004, 03:19 AM
What's the use of the clock variable?

I think Dingbat doesn't want the timer clock. As I've mentioned, I put it for tracking/debugging purposes only. They should be removed in the actual code.

- Remove timerClock declaration
var xScroll, yScroll, timerPoll, timerRedirect, timerClock;

- Remove 2 instances of this:
//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

- Remove span
Time: <span id="clock" style="font-weight:bold">0</span>

Willy Duitt
02-20-2004, 04:48 AM
I didn't see a need to remove the tracking and felt it would be handy to have in the event I would want to use the script myself in the future and needed to check if it was working.

FWIW: This bookmarklet can be used to return the clock variable value


javascript&#58;var globalvar=prompt('Read which variable?','');if(globalvar)try{alert(globalvar+' = '+eval(globalvar)+' ('+typeof(eval(globalvar))+')');}catch(e){alert('Global variable \''+globalvar+'\' does not exist.');}


.....Willy

Edit: Tried to fix the line break in the bookmarklet.

glenngv
02-20-2004, 05:06 AM
Originally posted by Willy Duitt
I didn't see a need to remove the tracking and felt it would be handy to have in the event I would want to use the script myself in the future and needed to check if it was working.
.....Willy

You are talking from the point of view of the web developer not the end-user. You even posted a bookmarklet to check a global variable. What I was talking about was when the application is deployed, the tracking script block should be removed if not needed.

Dingbat
02-20-2004, 08:18 AM
To Glenn & Willy,

:D My thanks to you guys. The script is now working as I wanted in the first place. Your assistance is very much appreciated.:D :thumbsup:

With kindest regards,

The Dingbat:D :D

froglander
03-27-2008, 09:25 PM
I don't know that anyone still looks at these older threads, but I have a question about the idledetect.htm page. When I found that, I thought it was the answer to what I had been struggling with. However, I have one problem, the page that I am trying to detect idle time on is one that will be contained inside an iframe (it is a .exe 'page' that is used for secure stuff at a school) and the idle detection does not work inside the iframe. Any suggestions?

Thanks a million!

glenngv
03-31-2008, 05:48 PM
Can you elaborate on your problem? Do you want to make the script working in both the main page and the iframe or in the iframe only?

If in the iframe only, just put the script inside the iframe page. And if you want to redirect the page to the main window and not to the iframe, then you need to change the redirect line to:


timerRedirect = setInterval("parent.location.href='anotherpage.htm'",10000); //set timed redirect

You can also use top instead of parent if you want to open in the outermost window and you have nested frames.

If you need to idle detect in both the main page and iframe, the script needs to be modified further.

Let me know what you need.

froglander
04-01-2008, 07:05 PM
Some of the pages that I want to detect idle time are ones that I am not able to modify. They are contained on a secure server and it is a .exe file that does things like student registration. What I am trying to do is get rid of a popup window that serves as a warning to students to remember to logout.

The main problem is that some of the student toolbox pages that I want to detect idle time on are generated by a file called "rqserver.exe" that I have no access to. I was trying to locate the pages generated by this application inside an iframe so that I could display the warning depending on idle time. I don't have to worry about a session time out, just a local, client-based redirect based on idle time.

Thanks so much for your help!

glenngv
04-01-2008, 10:32 PM
Are the main page and the iframe page in the same domain? If they are, there could be a solution.

froglander
04-03-2008, 03:48 PM
Yes, as far as I can tell, all the pages are in the same domain.

glenngv
04-03-2008, 06:15 PM
Try this:


<iframe src="rqserver.exe" onload="detectIdle(this.contentWindow);"></iframe>


Then replace these lines:

document.onmousemove=initRedirect;
document.onclick=initRedirect;
document.onkeydown=initRedirect;
window.onload=initRedirect;
window.onresize=initRedirect;


with this function:

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.

froglander
04-09-2008, 11:36 PM
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 :) )

glenngv
04-10-2008, 02:09 AM
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.

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?" :))

froglander
04-10-2008, 04:24 PM
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?"

glenngv
04-10-2008, 06:25 PM
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?")

froglander
04-10-2008, 06:39 PM
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)


/*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


<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"

glenngv
04-10-2008, 07:21 PM
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:

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? :)")

glenngv
04-10-2008, 08:16 PM
And I forgot, you also need to modify the initRedirect function:


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;
...
}
...
}

froglander
02-19-2009, 08:11 PM
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?

felixthebear
08-10-2009, 03:18 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum