【问题标题】:Google Transliterate API not working in mobile ChromeGoogle Transliterate API 在移动 Chrome 中不起作用
【发布时间】:2017-03-17 07:39:54
【问题描述】:

我编写了一个代码,使用 Google Transliterate 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>

【问题讨论】:

  • 如何修复它? @himadri
  • @JohnySharma 我无法修复它。所以,留下了这个想法。

标签: javascript google-chrome google-translate


【解决方案1】:

不同的应用程序有时需要为使用不兼容浏览器的用户提供不同的行为。 Transliterate API 提供了一个全局方法 google.elements.transliteration.isBrowserCompatible() 来检查兼容性,但它在检测到不兼容的浏览器时没有任何自动行为。出于可用性目的,您应该检测不兼容的浏览器,如果检测到,则显示错误消息。

【讨论】:

  • 我勾选了这个选项。请参考我更新的代码。它说它是兼容的,但仍然没有得到输出。
  • 我也面临同样的问题。它在 chrome 桌面上运行良好,但在 chrome mobile 上运行良好。
猜你喜欢
  • 2019-03-20
  • 1970-01-01
  • 2013-11-04
  • 1970-01-01
  • 1970-01-01
  • 2015-12-17
  • 2015-10-09
  • 2018-08-29
  • 1970-01-01
相关资源
最近更新 更多