javascript 如何管理跨浏览器兼容性问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4836737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:02:48  来源:igfitidea点击:

how to manage cross browser compatibility issues

javascripthtmlcsscross-browser

提问by newdeveloper

I am new to development. I want to know that how we can manage the cross browser compatiability problems. for example some times it happens that same code is working with firefox but not with IE. I had an issue that one of my code of downlao

我是开发新手。我想知道我们如何管理跨浏览器兼容性问题。例如,有时会发生相同的代码与 firefox 一起工作但不适用于 IE。我有一个问题,我的一个 downlao 代码

回答by Rob

Whenever anyone says they have "cross browser issues", they almost always mean "it doesn't work in IE". Frequently, the developer uses IE as their reference for how things work which is the worst thing they could do since IE is 13 years behind all other browsers in modern standards and compliance and inept at best.

每当有人说他们有“跨浏览器问题”时,他们几乎总是指“它在 IE 中不起作用”。通常,开发人员使用 IE 作为他们工作原理的参考,这是他们能做的最糟糕的事情,因为 IE 在现代标准和合规性方面比所有其他浏览器落后 13 年,而且充其量也无能为力。

Therefore, always use a modern browser (anything but IE) to initially test your markup. Along with validation of HTML and CSS, this will make your code work everywhere in most cases. Then you know your code is written correctly. As you go along, look in IE to see how it screws everything up but the quirks and bugs of IE are well known, as are the hacks to fix it.

因此,始终使用现代浏览器(IE 除外)来初步测试您的标记。随着 HTML 和 CSS 的验证,这将使您的代码在大多数情况下无处不在。然后你知道你的代码是正确编写的。随着您的进行,在 IE 中查看它是如何搞砸一切的,但 IE 的怪癖和错误是众所周知的,修复它的技巧也是如此。

Never, ever trust IE to do anything right. Do NOT fall for the fallacy that IE9 will be any savior either.

永远,永远不要相信 IE 会做正确的事情。不要误以为 IE9 将成为任何救星。

回答by udo

there are 2 possibilities when it comes to cross-compatibility:

在交叉兼容性方面有两种可能性:

  • handle cross-compatibility by yourself -> this is almost impossible for non-experts (keep in mind that you have to know how every browser is interpreting HTML/CSS/JS)
  • use a javascript library like:
  • 自己处理交叉兼容性 -> 这对于非专家来说几乎是不可能的(请记住,您必须知道每个浏览器如何解释 HTML/CSS/JS)
  • 使用 javascript 库,如:

the library will handle cross-compatibility ;)

该库将处理交叉兼容性;)

回答by michael bashagi

for IE u can use this little technique..:

对于 IE,你可以使用这个小技巧..:

 <!--[if IE]>
            <link rel="stylesheet" type="text/css" href="file.css"/>
 <![endif]-->

it was given out by microsoft...it worked for me!

它是由微软发布的...它对我有用!