我们经常会遇到js ie浏览器不兼容打不开网页,这也是很头疼的一件事,以下是我整理的最常见的浏览器不兼容问题的源头,希望对大家有帮助。
1、table问题
在动态新增tr或者td时,createelement()一般用appendchild();都不生效,解决办法是用新增tbody,如
var table=document.createelement(table);
var tvody=document.createelement(tbody);
var tr=document.createelement(tr);
var td=document.createelement(td);
table.appendchild(tbody.appendchile(tr.appendchild(td)));
2、innerhtml的问题
在ie中不支持动态的写table的innerhtml,但是支持p或者span的innerhtml动态读写。
3、设置样式问题
内敛样式:如果obj.setattribute(stylename);stylename对应的样式不会生效。解决方法:obj.style.csstext=stylename;
外部样式:obj.setattribute(class:classname);classname对应的外部样式照样不会生效。解决办法:obj.setattribute(classname,classname);
4、设置属于元素的事件
对于一个文本obj,ie不支持obj.setattribute(onclick,functon()),设置它的onclick属性做法。解决办法:obj.onclick=function(){}。注意的是:此处需要放一个匿名的函数
5、动态创建单选按钮
用create和setattribute()是解决不了问题的。解决办法:直接document.createelement(<input type='radio' name='myradio'>);来的更痛快一些
6、最后就是用document判断浏览器是否为ie的一个方法,document.uniqueid,因为只有ie唯一能识别uniqueid
ie的兼容性,更改解析模式
百度源代码如下
<!doctype html>
<html xmlns=http://www.w3.org/1999/xhtml xmlns:bd=http://www.baidu.com/2010/xbdml>;
<head>
<meta http-equiv=content-type content=“text/html;charset=utf-8″>
<meta http-equiv=x-ua-compatible content=ie=emulateie7>
<title>百度一下,你就知道 </title>
<script>var wpo={start:new date*1,pid:109,page:‘superpage’}</script>
<meta http-equiv=x-ua-compatible content=ie=emulateie7>
可以打开百度,右键查看源码看下!我们可以看下文件头是否存在这样一行代码!
这句话的意思是强制使用ie7模式来解析网页代码!
<meta http-equiv=“x-ua-compatible” content=“ie=8″>
2. google chrome frame也可以让ie用上chrome的引擎:
<meta http-equiv=“x-ua-compatible” content=“chrome=1″ />
3.强制ie8使用ie7模式来解析
<meta http-equiv=“x-ua-compatible” content=“ie=emulateie7″><!– ie7 mode –>
//或者
<meta http-equiv=“x-ua-compatible” content=“ie=7″><!– ie7 mode –>
4.强制ie8使用ie6或ie5模式来解析
<meta http-equiv=“x-ua-compatible” content=“ie=6″><!– ie6 mode –>
<meta http-equiv=“x-ua-compatible” content=“ie=5″><!– ie5 mode –>
5.如果一个特定版本的ie支持所要求的兼容性模式多于一种,如:
<meta http-equiv=“x-ua-compatible” content=“ie=5; ie=8″ />
设定网站服务器以指定预设兼容性模式
如果服务器是自己的话,可以在服务器上定义一个自订标头来为它们的网站预设一个特定的文件兼容性模式。这个特定的方法取决于你的网站服务器。
录入,下列的 web.config文件使microsoft internet information services (iis)能定义一个自订标头以自动使用ie7 mode来编译所有网页。
另外还有一起其他的解决方案,例如google的
ie7 – js中是一个javascript库(解决ie与w3c标准的冲突的js库),使微软的internet explorer的行为像一个web标准兼容的浏览器,支持更多的w3c标准,支持css2、css3选择器。它修复了许多的html和css问题,并使 得透明png在ie5、ie6下正确显示。
使ie5,ie6兼容到ie7模式(推荐)
<!–[if lt ie 7]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.0(beta)/ie7.js” type=”text/javascript”></script>
<![endif]–>
使ie5,ie6,ie7兼容到ie8模式
<!–[if lt ie 8]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.0(beta)/ie8.js” type=”text/javascript”></script>
<![endif]–>
使ie5,ie6,ie7,ie8兼容到ie9模式
<!–[if lt ie 9]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.1(beta4)/ie9.js”></script>
<![endif]–>
解决png显示问题
只需将透明png图片命名为*-trans.png
注意:此方法对背景平铺(background-repeat)和背景(background-position)无法起到任何作用,默认会占满整个容器。
<meta http-equiv=”x-ua-compatible” content=”ie=edge,chrome=1″ />
创建html5时发现这么一句话,不知其什么意思,百度如下:
这 样写可以达到的效果是如果安装了gcf,则使用gcf来渲染页面,如果没安装gcf,则使用最高版本的ie内核进行渲染。google chrome frame(谷歌内嵌浏览器框架gcf)。这个插件可以让用户的ie浏览器外不变,但用户在浏览网页时,实际上使用的是google chrome浏览器内核,而且支持ie6、7、8等多个版本的ie浏览器。
相关推荐:
ie浏览器下常见的css兼容问题
ie与火狐中常见的兼容问题
妙味课堂js高级专题篇视频教程
以上就是ie不兼容打不开网页怎么办?js浏览器不兼容问题解决技巧的详细内容。