Prevent Safari (iPhone) to show an URL bar on form

2019-09-19 10:35发布

问题:

I have found several javascript fixes to hide the Safari URL bar, great.

However it seems that form input fields tend to toggle it visible again if you've hidden it previously.. Is there a way to prevent this behaviour?

If it's not possible I guess I have to add an eventlistener that gives me a style hook on the URLs bar whereabouts..

回答1:

I've found another solution

$('body')
    .on('touchstart', 'input', function(e) {
        e.target.focus();
        return false;
    })
    .on('focus', 'input', function() {
        window.scrollTo(0, 0);
        return false;
    });

Address bar doesn't show at all with this code



回答2:

Found a fix..

setTimeout(function () {
    window.scrollTo(0, 1);
}, 500);

$(document).ready(function(){
    $('input').click(function(){
        window.scrollTo(0,0);
    });

stops the input behaviour..