views:

751

answers:

2

I'm developing a project in which I need to change the language according to the flag I click using AJAX. It's working fine in IE7 but it shows an error when I run it in IE6.

     <html>
<head>
    <script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;

    <script language="javascript">

  google.load("language", "1"); 

function fnTrans(strTransText,strTransField, strTransFLang, strTransTLang)
{

    google.language.translate(strTransText, strTransFLang, strTransTLang, function(result) {
      var strcontainer = document.getElementById(strTransField);
      strcontainer.innerHTML = result.translation ;

      });
}

function initialize(strToTxtBox, strFromTxtBox) {
    var x = window.location.toString();
    var strLang = x.substring(x.indexOf("=")+1);
    if((x.indexOf("="))==-1) return;
    strFLang = strLang.substring(0,2)
    strTLang = strLang.substring(strLang.indexOf("-")+1);
    var strText = document.getElementById(strFromTxtBox).innerHTML;

    if(strFLang != 'en')
     fnTrans(strText,strFromTxtBox, 'en',strFLang)

    fnTrans(strText,strToTxtBox, strFLang,strTLang) 
}

function fnhi()
{
    var label=document.getElementsByTagName("label");
    var count=label.length;
    var x = window.location.toString();
    var strLang = x.substring(x.indexOf("=")+1);
    if((x.indexOf("="))==-1)
         return;
    for(var i=0;i<count;i++)
          {
     initialize(label[i].id,label[i].id);
    }
document.getElementById("curlang").value=strTLang;
}

function fnClick(lang)
{
    if(lang=="") return;
    var curlang=document.getElementById("curlang").value;
    if(lang==curlang) return;
    window.location='language.php?strLang=' + curlang+'-'+lang;
}

    </script>
    </head>
    <body onload="fnhi()">
    <input type="hidden" id="curlang" value="en" size="3">
    <img src= "langauage.gif" use ="#map">
    <map name="Map">
        <area shape="rect" alt="Arabic" value="ar" coords="36,6,62,19" href="#" onclick="fnClick(this.value);">
        <area shape="rect" alt="Chinese" value="zh" coords="66,6,90,20" href="#" onclick="fnClick(this.value);">
        <area shape="rect" alt="German" value="de" coords="95,6,121,21" href="#" onclick="fnClick(this.value);">
    </map>


    </body></html>
A: 

It is not clear what is the question. Therefore I am guessing. If you want to do something in javascript browser dependant then you can ask from which browser the request have been sent.

<html>
<body>

<script type="text/javascript">
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

document.write("Browser name: "+ browser);
document.write("<br />");
document.write("Browser version: "+ version);
</script>

</body>
</html>

Then adding "if" statements you can "customize" the behaviour dependent the browser. Anyway I DO NOT ADVICE TO DO THIS because you have to maintain your code for all the browsers. Also you have to test different browsers and browser versions.

A possible solution is tu use some javascript libraries which are crossbrowser like GWT from Google.

Luis

Luixv
A: 

You should try http://code.google.com/p/jquery-translate/ instead!

Emil Stenström