简体   繁体   中英

Disable iOS double tap spacebar from browser

In iOS, there is native functionality that whenever the user double taps the spacebar and there is already content in the input field, it replaces what should be a double space with a full stop and a space.

I'm using Angular and ng-change to check for invalid characters when the field gets changed.

My question is - is there any way from a browser point of view to disable this functionality? If not - is there any hacks/ways around it in which I could replace the full stop and the space because at the moment, when I double tap the spacebar it doesn't seem to fire the function bound to ng-change.

This works.

var prevTime = 0, prevKey = 0;
document.querySelector("input").addEventListener("keyup", function (e) {
    if (Date.now() - prevTime < 1000 && prevKey == 32 && e.keyCode == 32) {
        var txt = this.value.split("");
        if (txt[txt.length - 2] == ".") {
            txt[txt.length - 2] = " ";
            this.value = txt.join("");
        }
    }
    prevTime = Date.now(); prevKey = e.keyCode;
});

http://jsfiddle.net/DerekL/YKz4N/

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