1

Consider the below code snippet that simply disables all buttons on a webpage:

<script>
    var inputs = document.getElementsByTagName('button');
    for (var i = 0; i < inputs.length; i++) {
            inputs[i].disabled = true;
    }

    var seconds = 0;
    setInterval(calculateSeconds, 1000);
    function calculateSeconds()
    {
        seconds += 1;
        if(seconds > 5)
        {
            var inputs = document.getElementsByTagName("button");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].disabled = false;
            }
        }
    }
</script>

Aside from the fact that this is not really a cool, well-written or purposeul piece of code, it should work and it does work on all browsers in Windows Desktop and on Android, except for browsers running in iOS; I tested this on an iPhone using Chrome and Safari and it does not work. I cannot find the cause of this, none of syntax is deprecated or unsupported, according to http://caniuse.com/. It's driving me crazy. No CSS is used on the website I am testing. It doesn't work on <button> tags, nor on <input type="button"> tags, nor on <input type="submit"> tags.

Does anyone have any tips, resources or pointers to why this is not working on iOS devices?

Zimano
  • 1,870
  • 2
  • 23
  • 41

1 Answers1

3

Perhaps try again to use a input instead of a button but instead of setting the attribute directly insteed use removeAttr("disabled") instead of setting it to false and use inputs[i].setAttribute("disabled","disabled") instead of .disabled=true

When I googled button disabled ios, I saw several posts mentioning issues with safari and <button> so perhaps there are issues with it

Also there are many discussions about DOM 'disabled' property in javascript

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Thank you! Could you perhaps explain why setting the attribute directly doesn't work? – Zimano Nov 07 '19 at 16:44
  • I have not found any documentation why it is so, it is just my experience that such things can become obsolete in some browsers that only want to use the current standard - there is a lot of confusion about disabled="disabled" disabled as a standalone attribute and .disabled=false etc - for example here https://stackoverflow.com/questions/23701560/dom-disabled-property-in-javascript – mplungjan Nov 07 '19 at 16:51