Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my Bing Translate code work perfect in all browsers except Google Chrome?

I've a simple Bing Translate example, but it does not work with google chrome.

I don't understand whether it is a bing problem or my code is wrong.

This is the code of my example

<!doctype html>
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">  
   function translate() {
   document.getElementById('trans').innerHTML="";
   var text= document.getElementById('ori').value;
   window.mycallback = function(response) {
   document.getElementById('trans').innerHTML=response;
   }

   var languageFrom = document.getElementById("langpairFROM").value;
   var languageTo = document.getElementById("langpairTO").value;
   var s = document.createElement("script");
   s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=mycallback&appId=68D088969D79A8B23AF8585CC83EBA2A05A97651&from=" + languageFrom + "&to=" + languageTo + "&text=" + text;
document.getElementsByTagName("head")[0].appendChild(s);
   }
</script>
</head>

<body>
<center>


<select id="langpairFROM" STYLE=" font-size : 11pt">
  <option value="de">German</option>
  <option value="en">English</option>
  <option value="ru">Russian</option>                                         
</select>

<select id="langpairTO" STYLE=" font-size : 11pt">
  <option value="ru">Russian</option>
  <option value="de">German</option>
  <option value="en">English</option>  
</select>

<button type="input" onclick="translate()" >Translate</button> 

<div >
  <textarea id="ori" name="translate" ></textarea> 
</div>

<div id="translationField">
  <textarea id="trans" >Translated Text</textarea> 
</div
</center>
</body> 

</html> 

Here ist the jsfiddle example

like image 930
alisia123 Avatar asked Nov 21 '25 07:11

alisia123


1 Answers

Because you also has a <textarea> named translate.

Change either the function name or the <textarea> name:

JSFidde

PS. I assumed you use something like encodeURIComponent to "sanitize" your url in production code.

like image 87
Passerby Avatar answered Nov 22 '25 19:11

Passerby