javascript 谷歌翻译不适用于任何 IE,但适用于 Firefox 和 GoogleChrome

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30893732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 12:53:16  来源:igfitidea点击:

Google Translate Not working in Any IE but works in Firefox and GoogleChrome

javascripthtmlinternet-explorerxmlhttprequestgoogle-translator-toolkit

提问by Zane Z

I have tested this page in IE, Firefox, and Google Chrome. It works in all except IE. Can someone please tell me how to fix this, I have tried just about everything I could for the last two days.

我已经在 IE、Firefox 和 Google Chrome 中测试了这个页面。它适用于除 IE 之外的所有内容。有人能告诉我如何解决这个问题吗,过去两天我已经尝试了我能做的一切。

TRY THIS TEST PAGE

试试这个测试页

<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
Hello
<div id="google_translate_element"></div>
        <script type="text/javascript">
        function googleTranslateElementInit() {
                new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
            }
        </script>
        <script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</body>
</html>

When selecting a language it shows the choice picked but never completes the translation.. But works in FireFox and Google Chrome. IE just sits at 0% and just keeps spinning. Is anyone else experiencing the same issue?

选择一种语言时,它会显示所选择的选项,但从未完成翻译。但在 FireFox 和 Google Chrome 中有效。IE 只是处于 0% 并且一直在旋转。有没有其他人遇到同样的问题?

The error it throws in the console when switching languages is this:

切换语言时它在控制台中抛出的错误是:

XMLHttpRequest: Network Error 0x2f1c, Could not complete the operation due to error 00002f1c.

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

I have tried many things even going as far as something like this:

我已经尝试了很多事情,甚至像这样:

<div id="google_translate_element"></div>
        <script type="text/javascript">
        $.ajax({
  url:"http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit",
  type:"POST",
  data:"google_translate_element",
  contentType:"application/json; charset=utf-8",
  dataType:"json",
  success: function googleTranslateElementInit() {
                new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
            }

  })
        </script>

Please any help would be greatly appreciated!!

请任何帮助将不胜感激!

回答by Bob

In the code there is a link to the google translate file

在代码中有一个指向谷歌翻译文件的链接

//translate.google.com...

//translate.google.com...

When I put the full address into my browser it automatically downloaded a text file. I converted the .txt file into to a .js file then replaced the web link with a link to the js file and it worked fine. I hope this helps.

当我将完整地址输入浏览器时,它会自动下载一个文本文件。我将 .txt 文件转换为 .js 文件,然后用指向 js 文件的链接替换了 Web 链接,并且运行良好。我希望这有帮助。

回答by Zane Z

I have finally found the issue!! The new security update broke the translator. If you delete KB3058515 this will fix the problem. But now we have to figure out how to make it work with the update since users will not delete there security updates.

我终于找到问题了!!新的安全更新破坏了翻译器。如果您删除 KB3058515,这将解决问题。但是现在我们必须弄清楚如何使它与更新一起工作,因为用户不会删除那里的安全更新。

回答by Elwyn Jones

I have the same issue, I think this is more a case of having MS not following the same rules that Mozilla and Google do to achieve the same results. This is really an IE issue that they should resolve, They are one of three that are trying to protect users from the method by which http can strip https security. One example was given where a user logs in to his bank using http which then redirects to https giving someone access to redirect the user to a false bank account to gather his details. I am still laughing at the very idea that a bank would use http transport anyway. Banks should use secure connections for everything. But it doesn't solve our problem. I have advised my clients to use Firefox or Chrome until this matter is resolved, which is outside my ability.

我有同样的问题,我认为这更像是让 MS 没有遵循 Mozilla 和 Google 为实现相同结果所做的相同规则的情况。这确实是他们应该解决的 IE 问题,他们是试图保护用户免受 http 可以剥离 https 安全性的方法的三个问题之一。举了一个例子,用户使用 http 登录他的银行,然后重定向到 https,让某人可以将用户重定向到一个虚假的银行帐户以收集他的详细信息。我仍然在嘲笑银行无论如何都会使用 http 传输的想法。银行应该为所有事情使用安全连接。但这并不能解决我们的问题。我已经建议我的客户使用 Firefox 或 Chrome,直到这个问题得到解决,这超出了我的能力范围。

回答by Geoff S

I had the same issue and found some other discussions. It is related to the introduction of support for HTTP Strict Transport Security standard (HSTS) in IE11, included in security update KB 3058515.

我遇到了同样的问题,并找到了一些其他讨论。它与在 IE11 中引入对 HTTP 严格传输安全标准 (HSTS) 的支持有关,包含在安全更新 KB 3058515 中。

It looks like your options are:

看起来您的选择是:

  • get users to remove or disable KB 3058515
  • get Google to add their sites to Microsoft's HSTS preload list
  • get Google to enable HSTS through use of the Strict-Transport-Security HTTP header
  • (possibly) get your site added to Microsoft's HSTS preload list
  • 让用户删除或禁用 KB 3058515
  • 让 Google 将他们的网站添加到 Microsoft 的 HSTS 预加载列表中
  • 通过使用 Strict-Transport-Security HTTP 标头让 Google 启用 HSTS
  • (可能)将您的站点添加到 Microsoft 的 HSTS 预加载列表中

More discussion here: http://answers.microsoft.com/en-us/ie/forum/ie11-windows_7/google-translate-widget-not-working-in-internet/55f835e2-6460-46f3-8e71-9dbf3c3f5e49

更多讨论在这里:http: //answers.microsoft.com/en-us/ie/forum/ie11-windows_7/google-translate-widget-not-working-in-internet/55f835e2-6460-46f3-8e71-9dbf3c3f5e49

Microsoft KB article: https://support.microsoft.com/en-us/kb/3071338

Microsoft 知识库文章:https: //support.microsoft.com/en-us/kb/3071338

回答by Jeremy

This issue is tied to a June 2015 update of Internet Explorer. By downloading the July 2015 release: Version 11.0.9600.17914, Update Versions 11.0.21 (KB3065822) - the issue seems to have been resolved. Microsoft is aware of the issue as noted in their forums. I believe they addressed it with a fix in the July release.

此问题与 2015 年 6 月的 Internet Explorer 更新相关。通过下载 2015 年 7 月版本:版本 11.0.9600.17914,更新版本 11.0.21 (KB3065822) - 问题似乎已解决。Microsoft 已意识到其论坛中指出的问题。我相信他们在 7 月的版本中通过修复解决了这个问题。

A recommended fix for user might be to have them update their browsers, if auto update is not turned on.

如果未打开自动更新,建议用户修复可能是让他们更新浏览器。

回答by Dave Moore

I recently hit this issue on a website. Translator showed up normally in Firefox, Chrome and on mobile browsers, but nothing in IE 8-11. Our solution was a pretty simple fix (which I imagine will not be the care for most). We literally just had to flip the script link and the script function.

我最近在一个网站上遇到了这个问题。翻译器在 Firefox、Chrome 和移动浏览器中正常显示,但在 IE 8-11 中没有。我们的解决方案是一个非常简单的修复(我想大多数人都不会关心)。我们实际上只需要翻转脚本链接和脚本函数。

<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script>
  function googleTranslateElementInit() {
    new google.translate.TranslateElement(
        {pageLanguage: 'en'},
        'google_translate'
    );

    jQuery('.goog-logo-link').css('display', 'none');
    jQuery('.goog-te-gadget').css('font-size', '0');
  }
</script>

Became:

变成:

<script>
  function googleTranslateElementInit() {
    new google.translate.TranslateElement(
        {pageLanguage: 'en'},
        'google_translate'
    );

    jQuery('.goog-logo-link').css('display', 'none');
    jQuery('.goog-te-gadget').css('font-size', '0');
  }
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

This fixed the issue of not displaying in IE, but also didn't hurt Chrome or Firefox.

这修复了在 IE 中不显示的问题,但也没有伤害 Chrome 或 Firefox。

回答by Drivec

I would comment if i had enough rep.

如果我有足够的代表,我会发表评论。

I have the same issue, works fine on Chrome and Firefox but it just fails on IE.

我有同样的问题,在 Chrome 和 Firefox 上运行良好,但在 IE 上却失败了。

An alternative is the Microsoft Bing translator http://www.microsoft.com/translator/getstarted.aspx.

另一种选择是 Microsoft Bing 翻译器http://www.microsoft.com/translator/getstarted.aspx

If anyone could help us that would be appreciated

如果有人可以帮助我们,我们将不胜感激

回答by AJW

I'd also comment if I had enough rep.

如果我有足够的代表,我也会发表评论。

I have the same issue as well. For me, it started after IE updated to v.11.0.9600.17843 (update version 11.0.20). Google Translate widget was working fine in IE before that.

我也有同样的问题。对我来说,它是在 IE 更新到 v.11.0.9600.17843(更新版本 11.0.20)之后开始的。在此之前,谷歌翻译小部件在 IE 中运行良好。