Use of window.location doesn't work on iPad
Asked Answered
B

3

14

I'm using some JavaScript that will redirect the user to another URL after a fixed period of time. This is working well on all browsers but on an iPad 3 I have to test on it isn't working. The timeout fires and I call

window.location = "www.someurl.com"; 

and I've also tried

  window.location.href = "www.someurl.com";

I can see the URL in the browser changing to www.someurl.ocom but the browser doesn't actually go there - it stays on the same page.

Is there something iPad specific I have to do to make this work?

Thanks

Brecher answered 23/5, 2013 at 12:57 Comment(1)
Does window.location.assign("foo.html"); make a difference?Irremovable
S
19

try location.href = "...", should work on both

Shishko answered 23/5, 2013 at 13:3 Comment(1)
Thanks - worked like a charm. Whats significant about window.location that iOS doesn't like?Brecher
M
0

The right answer here is you are missing the protocol. window.location.href = "http://www.someurl.com"; should do the trick

Malformation answered 8/9, 2016 at 23:55 Comment(0)
L
0

For me changing https to http made it finally work. Following other answers I also:

  • have set the window.location.href
  • added return false; after my change

My redirects worked in every browser and platform i tried apart of chrome on ios. After changing the protocol, not the redirects work!

  document.addEventListener("DOMContentLoaded", function(event) {
     window.location.href = "http://bbc.co.uk";
     return false;
  });
Lipchitz answered 4/5, 2022 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.