setTimeout doesn't work on iPad using Safari

Posted on 2013-06-06
Last Modified: 2013-11-29
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:

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() {

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);


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?
Question by:geekdad1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 22

Expert Comment

by:Kim Walker
ID: 39227057
What does screensaver.cgi do? Is the setTimeout not executing or is screensaver.cgi not working?
LVL 22

Expert Comment

by:Kim Walker
ID: 39227125
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.

Author Comment

ID: 39227191
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.
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

LVL 22

Expert Comment

by:Kim Walker
ID: 39227238
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?

Author Comment

ID: 39227299
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.
LVL 22

Expert Comment

by:Kim Walker
ID: 39227441
It appears to be a known bug. I found this in an internet search.

Accepted Solution

geekdad1 earned 0 total points
ID: 39230432
The problem turns out to be related to whether it's an http site, or an https site.
setTimeout works on http sites, but doesn't work on https sites.

I guess I'll have to report this to the safari people for resolution.

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Several part series to implement Internet Explorer 11 Enterprise Mode
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question