you are here: codestackercodes [RSS] → tag browser [RSS]

detecting ie version with jquery

var IE = $.browser.msie, IEv = $.browser.version;

if (IE) { //could be improved

    var IE6 = parseInt(IEv) == 6,
        IE7 = parseInt(IEv) == 7, 
        IE8 = parseInt(IEv) == 8, 
        IE9 = parseInt(IEv) == 9;
}

//Usage:


if (IE) {
    //Do something for all IE versions

}
if (IE7) {
    //Do stuff just for IE7

}
if (IE7 || IE8) {
    //Do stuff just for IE7 or IE8

}
if (!IE6) {
    //Do something if not IE6

}

placeholder attribute for inputs in IE

require jquery and modernizer

if(!Modernizr.input.placeholder){
	$("input").each(function(){
		if($(this).val()=="" && $(this).attr("placeholder")!=""){
			$(this).val($(this).attr("placeholder"));
			$(this).focus(function(){
				if($(this).val()==$(this).attr("placeholder")) $(this).val("");
			});
			$(this).blur(function(){
				if($(this).val()=="") $(this).val($(this).attr("placeholder"));
			});
		}
	});
}

css hacks for everyone

.test {
     color: #000000; /* All Browsers */
     color: #FFF000\9; /* All IEs */
     *color: #FFFF00; /* IE6 and IE7 */
     color: #0000FF\0; /* Only IE8 */
     color: #00FFFF!important; /* Only IE7 */
     _color: #FF0000; /* Only IE6 */
     [color: #000000; /* Safari, Chrome */
}

resize browser

$(document).ready(function(){

$(window).bind("resize", resizeWindow);
function resizeWindow( e ) {
	var newWindowHeight = $(window).height();
	$("#container").css("min-height", newWindowHeight );
}

});

ie 6 and 7 selectors hack

* html #selector {property:value;} /* Only IE6 and lower will see this */
*+html #selector {property:value;} /* Only IE7 will see this */

hover for ie 6

/* IE6 - pseudo class :hover */ 
$(document).ready(function(){ 
	if(jQuery.browser.msie && jQuery.browser.version<7){ 
		$('[class*="bla"]').hover( 
		function () { 
			$(this).addClass('hover'); 
		}, 
		function () { 
			$(this).removeClass('hover'); 
		} 
		); 
	} 
});

fixing the ridiculous auto-padding in ie (win) submit buttons

ie sux!

input { overflow: visible; }

set iframe background with javascript

var iframeDoc;
if (window.frames && window.frames.preview_frame && (iframeDoc = window.frames.preview_frame.document)) {
	iframeDoc.body.style.backgroundColor="#DADADA";
}

detect ie function

function isIE() {
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

1kb ie 6 png fix hack

create a 1x1 'clear.gif' image

var clear="images/clear.gif" //path to clear.gif


pngfix=function(){var els=document.getElementsByTagName('*');var i_p=/\.png/i;var i=els.length;while (i-- >0){var el=els[i];var es=el.style;if(el.src&&el.src.match(i_p)&&es.filter==''){el.height = el.height;el.width = el.width;es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src = clear;}else{var elb=el.currentStyle.backgroundImage;if(elb.match(i_p)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage="none";}}if (el.currentStyle.position!='absolute' && !es.filter && !el.tagName.match(/(body|html|script)/gi)) es.position="relative";if (es.filter&&el.currentStyle.position=="relative") es.position="static";}}
window.attachEvent('onload',pngfix);
Displaying all 10 Code