Link to home
Start Free TrialLog in
Avatar of Doug Poulin
Doug PoulinFlag for Canada

asked on

setTimeout doesn't work on iPad using Safari

We have a web app that uses setTimeout to blank out the screen after 15 minutes of non use. It's a medical application so this is an important feature.  It works fine in every browser except Safari on a mobile device (ipad, etc).

The original code was as follows:

setTimeout("WindowClose()",900000);
function Windowclose() {
     parent.main.location.href = "/cgi-bin/screensaver.cgi";
}

This works fine except on the ipad.

I scanned the Net and found this as a solution which works, but also not on the ipad.

sTimeout = setTimeout(function() {
   parent.main.location.href="/cgi-bin/screensaver.cgi";
}.bind(this),900000);

setTimeout.prototype.bind = function(parent) {
   var f = this;
   var args = [];

   for (var a = 1; a < arguments.length; a++) {
       args[args.length] = arguments[a];
   }

   var temp = function() {
      return f.apply(parent, args);
   }

   return(temp);
}


That works fine everywhere else except again on the iPad.

Does anyone have an example of some working code for the iPad or tell what's wrong with what I'm doing?
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

What does screensaver.cgi do? Is the setTimeout not executing or is screensaver.cgi not working?
I also have not been able to find any documentation regarding the "main" property of the parent document. What are you expecting to reference by "parent.main".

Why is it necessary for you to reference the parent document. Is this being executed from an embedded iframe?

When you say "everywhere but the iPad" does that mean it works on other Apple products such as laptops and desktop computers running MacOS?

I'm afraid there isn't enough information here to offer any suggestions.
Avatar of Doug Poulin

ASKER

Screensaver.cgi  just replaces the page in the main frame with a page that requires a password to continue.

It's not an iframe just a regular frame.  The frame is called main hence the parent.main reference.

The initial code (and for that matter the newer more complicated version) works, with IE, Firefox, Safari on windows and MacOS.  The only version that it doesn't work on is Safari on a mobile platform.  (iPad, iPhone, etc).

It would appear the setTimeout is not working.  Screensaver.cgi is never called.
So you're using frames and framesets? Are you using the frameset doctype?

Have you determined whether the setTimeout is not executing or if the code being executed is generating an error?
I changed the function to issue an alert instead of trying to change the frame document.  No alert message was displayed.  So I have to assume the setTimeout code is not executing.
It appears to be a known bug. I found this in an internet search.
ASKER CERTIFIED SOLUTION
Avatar of Doug Poulin
Doug Poulin
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial