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
Google Translate iframe workaround
提问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 iframe
url to translated page like:
这是谷歌翻译的真正限制或政策。您不能重写 iframe 内容。但是您可以做的一件事是将iframe
url更改为已翻译的页面,例如:
<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-security
param, 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
- Create empty iframe.
- Ajax the second iframe content already translated by google translator.
- Dump the response of the ajax into empty iframe.
- 创建空 iframe。
- Ajax 已由谷歌翻译器翻译的第二个 iframe 内容。
- 将 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
-500
so it hides the layer off the page with the Google dropdown selector in it.
您可以创建一个图层并将翻译器代码放入其中并放置该图层,top
-500
以便将图层隐藏在包含 Google 下拉选择器的页面之外。