如何以编程方式检查浏览器是否将某些字符视为JavaScript中的RTL?
也许创建一些透明的DIV并查看文本的放置位置?
一点背景.Unicode 5.2增加了Avestan字母表支持.因此,如果浏览器支持Unicode 5.2,它会将U + 10B00等字符视为RTL(目前只有Firefox支持).否则,它会将这些字符视为LTR,因为这是默认值.
我如何以编程方式检查这个?我正在写一个Avestan输入脚本,如果浏览器太笨,我想覆盖bidi方向.但是,如果浏览器确实支持Unicode,则不应覆盖bidi设置(因为这将允许混合Avestan和Cyrillic).
我目前这样做:
var ua = navigator.userAgent.toLowerCase();
if (ua.match('webkit') || ua.match('presto') || ua.match('trident')) {
var input = document.getElementById('orig');
if (input) {
input.style.direction = 'rtl';
input.style.unicodeBidi = 'bidi-override';
}
}
Run Code Online (Sandbox Code Playgroud)
但是,显然,在Chrome和Opera开始支持Unicode 5.2之后,这会使脚本不太可用.