[英]Browser compatibility between IE6 and IE7
I'm developing a project in which I need to change the language according to the flag I click using AJAX. 我正在开发一个项目,在该项目中,需要根据我使用AJAX单击的标志来更改语言。 It's working fine in IE7 but it shows an error when I run it in IE6.
在IE7中运行正常,但在IE6中运行时显示错误。
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<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>
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.
如果您想在依赖JavaScript的浏览器中执行某些操作,则可以询问从哪个浏览器发送了请求。
<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. 然后添加“ if”语句,您可以“自定义”与浏览器相关的行为。 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. 一个可能的解决方案是使用一些跨浏览器的JavaScript库,例如Google的GWT。
Luis 路易斯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.