Disabling Previous and Next buttons in Mobile Safari

后端 未结 4 1676
有刺的猬
有刺的猬 2020-12-05 20:09

Is it possible to disable the \'next\' and \'previous\' buttons in Mobile Safari when focused on an input field? I\'ve been trying the method of setting all fields to

4条回答
  •  抹茶落季
    2020-12-05 20:50

    I could see that this ticket is an old one, but the above proposed answer doesn't work for me as iPhone opens the select options list before the focus event is called. So I have used the below code and it worked like charm for me.

    My working solution for this:

    if (navigator.userAgent.toLowerCase().indexOf("iphone") ==-1) {
        }else{
            $(document).on('touchstart', 'input, select', function() {
                $('select, input').not(this).attr('disabled', 'disabled');
            }).on('blur', 'input, select', function() {
                $('input, select').removeAttr('disabled');
            });
        }
    

    This solution disables prev and next buttons in iPhone. If you want to change the selectors targeting only the specific input elements, you just need to modify it in the above code.

    I'm targeting only iPhone (may be you can use different condition to test if it's iphone or not). Used 'touchstart' as it gets triggered before the 'focus'. On blur, I'm enabling the input & select fields back.

    Hope this answer helps.

提交回复
热议问题