javascript 谷歌翻译 iframe 解决方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22936421/
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 00:03:08  来源:igfitidea点击:

Google Translate iframe workaround

javascriptjquerygoogle-translatemachine-translation

提问by Hyman Johnson

I'm using Google Translate tools to translate a web page and I also have an iframe on this page, that is not obviously translated with the page.

我正在使用谷歌翻译工具来翻译一个网页,我在这个页面上也有一个 iframe,它显然没有随页面一起翻译。

Is there a workaround, that any of you know, so I can have the iframe translated as well?

有没有你们知道的解决方法,以便我也可以翻译 iframe?

回答by XIMRX

This is a genuine limitation or policy of Google Translate. You can't rewrite iframe content. But one thing you can do is change iframeurl to translated page like:

这是谷歌翻译的真正限制或政策。您不能重写 iframe 内容。但是您可以做的一件事是将iframeurl更改为已翻译的页面,例如:

<iframe height="1200" width="600" src="http://translate.google.com/translate?hl=bg&ie=UTF-8&u=YOUR_IFRAME_URL&sl=de&tl=bg" align="middle" border="0">

回答by Flash Thunder

If you need to translate the page with iframes, you can:

如果您需要使用 iframe 翻译页面,您可以:

1. Use Bing Translator, that proxyfies request, so it wouldn't be cross domain.

1.使用Bing Translator,代理请求,不会跨域。

site:

https://www.bing.com/translator

plugin that uses it (not tested):

https://chrome.google.com/webstore/detail/translator/blndkmebkmenignoajhoemebccmmfjib

地点:

https://www.bing.com/translator

使用它的插件(未测试):

https://chrome.google.com/webstore/detail/translator/blndkmebkmenignoajhoemebccmmfjib

2. You can run your browser (if it's Chrome) with --disable-web-securityparam, so it would allow access to frames from other domains.

2. 您可以使用--disable-web-security参数运行您的浏览器(如果是 Chrome),因此它允许访问来自其他域的框架。

Please note that it's dangerous and should only be used on trusted sites.

请注意,这是危险的,只能在受信任的站点上使用。

回答by Merak Marey

  1. Create empty iframe.
  2. Ajax the second iframe content already translated by google translator.
  3. Dump the response of the ajax into empty iframe.
  1. 创建空 iframe。
  2. Ajax 已由谷歌翻译器翻译的第二个 iframe 内容。
  3. 将 ajax 的响应转储到空的 iframe 中。

$("#id_of_empty_iframe").load("http://translate.google.com/translate?hl=bg&ie=UTF-8&u=YOUR_IFRAME_URL&sl=de&tl=bg");

$("#id_of_empty_iframe").load(" http://translate.google.com/translate?hl=bg&ie=UTF-8&u=YOUR_IFRAME_URL&sl=de&tl=bg");

回答by sh2605

You could create a layer and put the translator code in it and put the layer top-500so it hides the layer off the page with the Google dropdown selector in it.

您可以创建一个图层并将翻译器代码放入其中并放置该图层,top-500以便将图层隐藏在包含 Google 下拉选择器的页面之外。