我已经编写了一段代码,它使用谷歌音译API将文本框内容音译为Gujarati。它在PC浏览器中工作得很好,在移动浏览器UC浏览器中也可以工作。我面临的问题是,当我在移动Chrome浏览器中运行相同的代码时,它不能工作。
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Google Transliterate API
google.load("elements", "1", {
packages: "transliteration"
});
function onLoad() {
var options = {
sourceLanguage: 'en',
destinationLanguage: ['gu'],
transliterationEnabled: true
};
if (google.elements.transliteration.isBrowserCompatible()) {
alert('compatible');
var control = new google.elements.transliteration.TransliterationControl(options);
var ids = ["idTitle", "idContent"];
control.makeTransliteratable(ids);
} else {
alert('not compatible');
}
}
google.setOnLoadCallback(onLoad);
</script>
<form action="index.php" method="post">
<label for="blogtitle">Title</label>
<input type="text" id="idTitle" name="txtTitle" value="" required>
<label for="content">Content</label>
<textarea id="idContent" name="txtContent" required> </textarea>
<input name="btnAdd" type="submit" value="Add">
</form>
发布于 2017-03-17 10:21:10
对于浏览器不兼容的用户,不同的应用程序有时需要不同的行为。音译API提供了一个全局方法google.elements.transliteration.isBrowserCompatible()来检查兼容性,但是当它检测到不兼容的浏览器时,它没有任何自动行为。出于可用性的考虑,您应该检测不兼容的浏览器,如果检测到,则显示错误消息。
https://stackoverflow.com/questions/42851829
复制相似问题