简体   繁体   中英

ios viewport initial-scale not honored after on-screen keyboard

I've got a non-responsive page I need to include via iframe. In order to show the entire iframe I dynamically set the viewport width and scale using javascript. When I'm ready to close the iframe I reset the viewport width and scale to the original values.

Normally this works fine. However, if the on-screen keyboard is opened (eg on text input focus) iOS refuses to honor any further scaling. It will honor the viewport resize, just not the initial-scale. Interestingly, if you rotate the device it will eventually honor the initial-scale.

I think this may just be an iOS bug. Any advice would be greatly appreciated.

So it seems the trick is simply to trigger the keyboard again. Once the keyboard opens the viewport scale you set will be honored immediately.

Getting the keyboard to popup is easier said than done. Basically you have to handle a real click event or mouseup event and then trigger a text input focus directly from the click handler ( http://jsfiddle.net/DLV2F/87/ ).

<input>
<p id="click">Click handler</p>
<p id="click-timeout">Click handler setting timeout</p>
<p id="mousedown">Mousedown handler</p>
<p id="mousedown-timeout">Mousedown handler setting timeout</p>
<p id="mouseup">Mouseup handler</p>
<p id="mouseup-timeout">Mouseup handler setting timeout</p>
<p id="extern-click-trigger">Clicking here will trigger click on the first 'Click Handler'</p>
<p id="tap">Virtual 'TAP' handler</p>
<p id="tap-triggering-click">Virtual 'TAP' handler triggering click on the first 'Click handler'</p>

<script>
function focus() {
    $('input').focus();
}
$(focus);
$(function() {
    $(document.body).load(focus);
    $('#click').click(focus);
    $('#click-timeout').click(function() {
        setTimeout(focus);
    });
    $('#mousedown').mousedown(focus);
    $('#mousedown-timeout').mousedown(function() {
        setTimeout(focus);
    });
    $('#mouseup').mouseup(focus);
    $('#mouseup-timeout').mouseup(function() {
        setTimeout(focus);
    });
    $('#extern-click-trigger').click(function() {
        $('#click').click();
    });
    $('#tap').bind('tapone', function() {
        focus();
    });
    $('#tap-triggering-click').bind('tapone', function() {
        $('#click').click();
    });

});
</script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM