首页 > 技术文章 > 该帖子会记录一些工作中用到的小方法..会时常更新...

xiuber 2016-08-16 11:38 原文

1.根据iframe内容自适应iframe高度.

var height_frame=document.getElementById('main');
height_frame.style.height=height_frame.contentWindow.document.body.scrollHeight+'px';

2.获取iframe内容的url

var height_frame=document.getElementById("main");
var url=height_frame.contentWindow.location.href;

 3.判断ie版本,让其在ie8以上版本操作。

$(document).ready(function(){
    var DEFAULT_VERSION = "8.0";
    var ua = navigator.userAgent.toLowerCase();
    var isIE = ua.indexOf("msie")>-1;
    var safariVersion;
    if(isIE){
        safariVersion =  ua.match(/msie ([\d.]+)/)[1];
    }
    if(safariVersion <= DEFAULT_VERSION ){
        alert("请使用IE8以上版本登录"); 
    }
});    

 4。css hack

(1)方式一 条件注释法
只在IE下生效
<!--[if IE]>
这段文字只在IE浏览器显示
<![endif]-->
只在IE6下生效
<!--[if IE 6]>
这段文字只在IE6浏览器显示
<![endif]-->
只在IE6以上版本生效
<!--[if gte IE 6]>
这段文字只在IE6以上(包括)版本IE浏览器显示
<![endif]-->
只在IE8上不生效
<!--[if ! IE 8]>
这段文字在非IE8浏览器显示
<![endif]-->
非IE浏览器生效
<!--[if !IE]>
这段文字只在非IE浏览器显示
<![endif]-->

 5.清除浮动的通用class

.clear {
    clear: both;
    display: block;
    overflow: hidden;
    visibility: hidden;
    width: 0;
    height: 0;
}

.clearfix:before, .clearfix:after {
    content: '.';
    display: block;
    overflow: hidden;
    visibility: hidden;
    font-size: 0;
    line-height: 0;
    width: 0;
    height: 0;
}

.clearfix:after {
    clear: both;
}

.clearfix {
    zoom: 1;
}

 

推荐阅读