"alert()" and "confirm()" not working with "apple-mobile-web-app-capable"
Asked Answered
A

8

24

Under iOS (currently 7.0), it looks like alert() and confirm() are not working when our web app is pinned to the home screen (aka using the meta tag apple-mobile-web-app-capable).

I found a user having a similar issue on twitter:

https://twitter.com/thomasfuchs/status/380137801259704320

Anybody has a temporary fix if it's really a bug in iOS 7?

Augustinaaugustine answered 19/9, 2013 at 19:40 Comment(1)
Wow ios 16.7 still has this issue.Benedicite
U
8

The JavaScript alert() and confirm() bugs are fixed as of iOS 7.0.3.

Uriia answered 22/10, 2013 at 22:40 Comment(2)
I'm on iOS 7.0.4 and this bug is still happening for me.Carrollcarronade
confirm() works for me on iOS 7.0.4 on iPhone 4S but didn't work on earlier iOS (not sure which 7.0.x I had before). Maybe the bug happens only on iPads.Eiten
S
14

We had a similar issue with alerts breaking our web app. The specific case was an alert which was triggered from the onchange of a select list. We put together a very simple test page like this:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">
    </head>
    <body>
        <select onchange="alert('broken!');">
            <option value="one">One</option>
            <option value="two">Two</option>
        </select>
    </body>
</html>

Running that page from Safari in an iPad and changing the select list triggers the alert then Safari freezes. You actually have to then close Safari. This affects Safari in general - your web app doesn't have to be pinned to the home screen. You should be able to test this on an iPad running iOS 7 on this test page http://jsbin.com/AGoTejA/1.

We have tested this on an iPad 2 (MC774B/A) and an iPad 3 (MD367B/A) and Safari crashes on both.

A hacky way to get around this is to use a setTimeout() to delay execution of the alert. The problem only seems to happen when Safari is trying to display the overlay which shows the select list items and an alert at the same time. confirm() is also broken in the same way.

Singer answered 23/9, 2013 at 12:54 Comment(2)
i got around this by using Alertify. Simple, and effective. fabien-d.github.io/alertify.js/0.4.0rc1Endothelium
This is really a great sample block. Have you reported this to radar.apple.com?Southwester
U
8

The JavaScript alert() and confirm() bugs are fixed as of iOS 7.0.3.

Uriia answered 22/10, 2013 at 22:40 Comment(2)
I'm on iOS 7.0.4 and this bug is still happening for me.Carrollcarronade
confirm() works for me on iOS 7.0.4 on iPhone 4S but didn't work on earlier iOS (not sure which 7.0.x I had before). Maybe the bug happens only on iPads.Eiten
L
5

I don't know if it is by design or a bug but I can confirm this is a real problem. One other thing to be aware of is that if the user has the option to save passwords enabled, any site that requires a login will fail because that prompt is also blocked. (you can try this with a simple form with a username and password box and nothing else and it simply won't submit). There are workarounds though for all three issues.

  1. Login - set autocomplete="off" in the form tag for the site, or detect that the site is running IOS7 and in fullscreen mode and apply this setting

    $('form').attr('autocomplete', 'off');
    
  2. Alerts and Confirms - you can either write a custom function in JavaScript or override the existing functions in much the same way as here: http://andrewensley.com/2012/07/override-alert-with-jquery-ui-dialog/. I like using Eric Martin's SimpleModal plugin which has a built in Confirm override, the bottom demo on http://www.ericmmartin.com/projects/simplemodal-demos/.

I hope some of that helps.

Lastditch answered 20/9, 2013 at 21:3 Comment(0)
U
4

I solved with a setTimeout

<select onchange="setTimeout(function(){alert('not broken!');},200)">
                <option value="one">One</option>
                <option value="two">Two</option>
            </select>

http://jsbin.com/iPuXiVA/4/

Anyway, seems this bug afflicts the iPad and not the iPhone.

Udell answered 21/10, 2013 at 19:28 Comment(1)
can confirm iphone 6 is affectedContusion
J
1

I had this happening for me with the following code:

const confirmation = window.confirm(message || 'Are you sure?');

The confirm would show up on PC (Edge browser), but not on iPhone (Safari browser)

I changed the code to the following (removed the window.):

const confirmation = confirm(message || 'Are you sure?');

And suddenly it was working again.

I am guessing that Apple got its own implementation of confirm that does not need the window.

Jaqitsch answered 26/5, 2020 at 15:19 Comment(0)
E
1

I noticed this today on iOS 16 – which will be released publicly in a few days. It quite likely was happening on previous versions-I just didn’t notice.

I had some debugging alerts that would show when I click certain buttons. They were working correctly until I navigated back using the swipe motion. After that all the logic surrounding the alert was occurring correctly, but the dialog box didn’t show.

And no it wasn’t reloading a previous version of the site as everything else was as expected.

If this is by design, I can’t imagine why.

Erstwhile answered 9/9, 2022 at 18:37 Comment(2)
I've been trying to solve this one for years. Not with much effort, but we have a submit button that gives you a confirmation "Are you sure you are ready to submit?" It works for 95% of users, but every couple of days we still get a mobile safari user that experiences this issue.Allopathy
Since you're getting this so frequently, would be very interested to hear if you still get it now that iOS 17 is public (since about 3 hours ago!)Erstwhile
I
0

I think that a bug related to the smooth hiding selection boxes animation. I do not like hacks, but this method works. Confirming called after 100 ms (this is enough for the time until the selection window closes)

var object;

$('form select').change(function()
{
    object = $(this);
    timer = setTimeout(confirmation, 100);
});

function confirmation()
{
    switch(object.val())
    {
        case 'post_approved':
        case 'post_delete':
        case 'thread_delete': object.parent('form').find('input[name=id]').val(object.parent('form').find('input[name=post_id]').val()); break;
        case 'user_delete_all': object.parent('form').find('input[name=id]').val(object.parent('form').find('input[name=user_id]').val()); break;
        default: return false; break;
    }

    if(object.parent('form').find('input[name=act]').val() === 'post_approved'  || (object.parent('form').find('input[name=act]').val() != '' && confirm('Вы уверены?')))
        object.parent('form').submit();
    else
        return false;
}
Illassorted answered 16/10, 2013 at 11:10 Comment(0)
C
0

Andersen is correct:

javascript alert() and confirm() bugs fixed as of iOS7.0.3

just installed and tested it myself.

While Apple was fixing the issue, I scrambled to find something to work around it, and ended up finding a js plugin called Alertify that I thought this was worthwhile to share. I think I'll use it from now on, regardless of the bug fix! It just makes alerts, prompts etc look really, really good. Thought it was worth sharing since readers of this post are likely using the standard browser alerts. I was stoked to stumble across it.

Codpiece answered 24/10, 2013 at 4:37 Comment(2)
I am using and iPad mini with iOS 7.0.3 and the issue is still present in Safari. It works on Chrome, though.Corby
I can also confirm that it is not working on two different types ipads with IOS 7.0.3Inductee

© 2022 - 2024 — McMap. All rights reserved.