I had a similar problem, after many studies, brains and help from this site, this is what I did. This prevents all [CTRL + A], backspace / delete errors from appearing in Firefox. Works great for me. May work for someone else. Sorry global namespace pollution.
function getBrowserInfo() { //function that returns an array with browser name at index 0, version at index 1 var N=navigator.appName, ua=navigator.userAgent, tem; var M=ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i); if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) { M[2]= tem[1]; } M = M ? [M[1], M[2]]: [N, navigator.appVersion, '-?']; return M; } function crossBrowserify() { //checks for browsers that lack support and adds the handler leaving compatible browsers like Firefox unaffected var browserInfoArr = getBrowserInfo(), browser = browserInfoArr[0], browserVersion = browserInfoArr[1]; if(browser.toLowerCase() == "safari" && browserVersion >= 8 && browserVersion < 9) { $(document).on("keypress", "input[type='text']", preventExcessCharacters); } } function preventExcessCharacters(e) { //fix for a bug in Mac OSX Safari 8 var $this = $(this), //caching element to prevent performance issues due to frequent DOM access mxLength = $this.attr("maxlength"); if(mxLength){ if (e.which < 0x20) { // e.which < 0x20, then it not a printable character // e.which === 0 - Not a character return; // Do nothing } if (this.value.length == mxLength) { e.preventDefault(); } else if (this.value.length > mxLength) { // Maximum exceeded // fix for copy paste bug this.value = this.value.substring(0, mxLength); } } } //set handler if browser lacks support crossBrowserify();
source share