iOS 11 Safari HTML-禁用“智能标点"吗? [英] iOS 11 Safari HTML - Disable "Smart Punctuation"?

查看:133
本文介绍了iOS 11 Safari HTML-禁用“智能标点"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种很好的方法来禁用iOS 11 Apple Keyboard生成的" Smart 标点符号"-在Safari中以HTML登录表单-特别是用户名字段?

Is there a good way to disable the "Smart Punctuation" the iOS 11 Apple Keyboard generates - in Safari on an HTML login form - username field in particular?

问题是我们的用户名中带有撇号的用户.在iOS 11上键入他们的用户名,却不知道他们无法登录的unicode的细微之处.

The problem is that we have users with apostrophes in their usernames. Typing their usernames on iOS 11 and not knowing the subtleties of unicode they are not able to sign in.

理想情况下,我们可以指示此类用户禁用智能引号或通过按住撇号键来键入正确的字符-但是我正在为幼儿设计教育软件,这是不可能的.

Ideally we could just instruct such users to disable smart quotes or type the proper character by holding down the apostrophe key - but I am working on educational software for small children and that is out of the question.

问题还在于,用户名中仅有少量用户使用实际的卷曲单引号,因此简单的替换图将不起作用-我们可以无法对用户名进行规范化,因为它们来自许多我们无法控制的外部系统/不能说太多话.

The problem is compounded by the fact that there are also a small selection of users with actual curly single quotes in their usernames, so a simple map of replacements won't work - and we can't canonicalize the usernames as they come from a number of external systems we don't control / can't have a lot of say over.

推荐答案

不幸的是,根据此MDN页面没有已知的Webkit <input><textarea>属性来禁用智能引用,但是您可以使用我从此质量检查派生的脚本编写补丁: a href ="https://stackoverflow.com/questions/45509709/how-to-disable-smart-quotes-for-textarea-fields-in-the-browser">如何在浏览器中禁用textarea字段的智能引号?

Unfortunately according to this MDN page there is no known Webkit <input> or <textarea> attributes to disable smart-quotes, but you can patch it with a script I've written derived from this QA: How to disable smart quotes for textarea fields in the browser?

window.addEventListener('DOMContentLoaded', attachFilterToInputs );

function attachFilterToInputs() {

    var textInputs = document.querySelectorAll( 'input[type=text], input[type=password], input[type=email], input[type=search], input[type=url], textarea, *[contenteditable=true]' );
    for( var i = 0; i < textInputs.length; i++ ) {
        textInputs[i].addEventListener( 'keypress', preventPretentiousPunctuation );
    } 
}

var conversionMap = createConversionMap();

function createConversionMap() {

    var map = {};
    // Open-quotes: http://www.fileformat.info/info/unicode/category/Pi/list.htm
    map[ 0x2018 ] = '\'';
    map[ 0x201B ] = '\'';
    map[ 0x201C ] = '"';
    map[ 0x201F ] = '"';

    // Close-quotes: http://www.fileformat.info/info/unicode/category/Pf/list.htm
    map[ 0x2019 ] = '\'';
    map[ 0x201D ] = '\"';

    // Primes: http://www.fileformat.info/info/unicode/category/Po/list.htm
    map[ 0x2032 ] = '\'';
    map[ 0x2033 ] = '"';
    map[ 0x2035 ] = '\'';
    map[ 0x2036 ] = '"';

    map[ 0x2014 ] = '-'; // iOS 11 also replaces dashes with em-dash
    map[ 0x2013 ] = '-'; // and "--" with en-dash

    return map;
}

function preventPretentiousPunctuation( event ) {

    if( event.key.length != 1 ) return;

    var code = event.key.codePointAt(0);
    var replacement = conversionMap[ code ];
    if( replacement ) {

        event.preventDefault();
        document.execCommand( 'insertText', 0, replacement );
    }
} 

这篇关于iOS 11 Safari HTML-禁用“智能标点"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆