如何检测不呈现.png透明度的浏览器 [英] How to detect a browser that dosen't render .png transparency

查看:104
本文介绍了如何检测不呈现.png透明度的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,根据一周的日期呈现图像。但是在IE6及更低版本以及其他一些浏览器中,它不会呈现png不透明度。因此,我想将其更改为litle,以便它将检测不呈现Alpha透明度的浏览器,并告诉他们加载此图像:img / horarios2.png。我已经尝试过制作它以便它排除IE6和更低的已知没有渲染,但后来我想到我可能不知道的所有其他浏览器也不会渲染任何需要的东西来统治它们也出去了。我不知道最好的方法来实现这一点,所以我对所有的游戏都开放。

I have this code that render's a image acording to the day of the week. But in IE6 and lower and probably some other browsers it won't render png opacity. So I want to change it a litle so that it will detect the browser's that don't render alpha transparency and tell them to load this image instead: "img/horarios2.png". Ive tried making it so that it would rule out IE6 and lower that are known for not rendering, but then I thinking about all the other browsers that I probably don't know about that don't render either and needed something that would rule them out also. I don't know the best way to acomplish this so im open to all sugestions.

$(document).ready (function horario () {
var date = new Date();
var weekday = (date.getDay());

if (weekday==0)
    document.getElementById('horarios').src = "img/domingo.png";
else if (weekday==4)
    document.getElementById('horarios').src = "img/quinta.png";
else if (weekday==5)
    document.getElementById('horarios').src = "img/sexta.png";
else if (weekday==6)
    document.getElementById('horarios').src = "img/sabado.png";
else 
    document.getElementById('horarios').src = "img/quarta.png";
});


推荐答案

我对此做了大量研究这个问题得出的结论是,在JavaScript中创建一个功能测试是不可行的,并且IE 6是唯一一个严重使用不支持PNG透明度的浏览器。在这种情况下,你最好的选择是加布里埃尔罗斯推荐的条件评论。可以在纯JavaScript中使用条件注释,我认为这是你想要的:

I've done a reasonable amount of research into this this issue and came to the conclusion that it was not feasible to create a feature test in JavaScript, and that IE 6 is the only browser in serious use that doesn't support PNG transparency. That being the case, your best bet is conditional comments, as recommended by Gabriel Ross. It is possible to use conditional comments in pure JavaScript, which I think is what you want:

var div = document.createElement("div");
div.innerHTML = "<!--[if lte IE 6]><i></i><![endif]-->";
var isIe6orLower = (div.getElementsByTagName("i").length == 1);

alert("Is IE 6 or lower: " + isIe6orLower);

更新2012年6月17日

请注意,IE 10 不支持条件评论 ,因此这种方法在IE的未来版本中不起作用。

Note that IE 10 will not support conditional comments, so this approach will not work in future versions of IE.

这篇关于如何检测不呈现.png透明度的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆