[英]Why does this code not work in IE & Safari?
I've been tasked with writing some code, that places a small icon in the top right corner of an Ad regardless of size. 我的任务是编写一些代码,无论尺寸大小,该代码都会在广告的右上角放置一个小图标。 Depending on the language of the user (in this case I'm using the browser language) it will change the icon (based on a bank of images on a server somewhere) and will subsequently change the URL of the click through for that image. 根据用户的语言(在这种情况下,我使用的是浏览器语言),它将更改图标(基于某处服务器上的图像库),并随后更改该图像的点击URL。 I know that I can get this to work by reading the OS language with the HTTP header, but I can't do this and it needs to be done server side. 我知道我可以通过使用HTTP标头读取OS语言来使其工作,但是我无法做到这一点,它需要在服务器端完成。 The script was written by me but the HTML was inherited by someone else - I also have the ability to edit both. 脚本是我写的,但HTML是别人继承的-我也可以同时编辑两者。
Currently the code works in Firefox, Chrome and Opera but will not work when I make the default browser language another European language (say French) in IE and Safari..!! 目前,该代码可在Firefox,Chrome和Opera中运行,但是当我在IE和Safari中将默认浏览器语言设为另一种欧洲语言(例如法语)时,该代码将无法工作。 This is driving me mad now so if you can help me I'd be so grateful. 现在这使我发疯,所以如果您能帮助我,我将非常感激。 On some advice, there is a live example here: 根据一些建议,这里有一个实时示例:
Live demo: http://jsfiddle.net/Juu7t/ 现场演示: http : //jsfiddle.net/Juu7t/
EDIT: Right so after playing around with the code, I still can't see why it doesn't work. 编辑:正确,所以在玩完代码后,我仍然看不到为什么它不起作用。 What is essentially happening is the default image will load (for IE and Safari) but it won't swap the image based on the browser language. 本质上发生的是将加载默认图像(适用于IE和Safari),但不会基于浏览器语言交换图像。 The JavaScript console doesn't show any errors and Firebug isn't helping me! JavaScript控制台未显示任何错误,Firebug并没有帮助我!
EDIT2: Right so I wrote this small function to test whether Internet Explorer is actually reading the language correctly. EDIT2:是的,所以我写了这个小函数来测试Internet Explorer是否实际上正在正确读取该语言。 (I'm using IE9): (我正在使用IE9):
function checkIE () {
if ((navigator.browserLanguage) || (window.navigator.language)) {
var testbrowser = navigator.browserLanguage || window.navigator.language;
alert(testbrowser);
}
}
checkIE();
Even when I change the language in IE to "French" ie "fr" it still returns "en-US"!! 即使我将IE中的语言更改为“法语”(即“ fr”),它仍会返回“ en-US”! am I doing something wrong or am I reading the wrong value from the navigator object?! 我做错了什么还是从导航器对象中读取了错误的值?
I am also looking for solution and I found the solution in a post as 我也在寻找解决方案,我在帖子中找到了解决方案
$.ajax({
url: "http://ajaxhttpheaders.appspot.com",
dataType: 'jsonp',
success: function(headers) {
language = headers['Accept-Language'];
nowDoSomethingWithIt(language);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.