Magic for old browsers

In the world of the web, new standards are constantly emerging. And because technological development occurs at an astonishing pace, older standards become incompatible and gradually face exclusion.

To put it simply, it’s like an older smartphone model that can’t be updated to the latest OS. Hasn’t everyone experienced something like product support ending?

Computers and smartphones have dedicated browser apps for viewing the internet, but there are different types of browsers. These are the icons you launch when browsing pages, such as Safari on iPhone or Chrome on Android.

For projects where time is limited, specifying “compatible only with the latest browsers” minimizes issues and ensures smooth progress. However, some companies still use older browsers internally for security reasons, so depending on the request, we may need to broaden the compatibility range.

Not all browsers are built to common standards, requiring individual handling.

For example, in HTML, conditional comments or CSS hacks. In JavaScript, polyfills are one such example. For reference, I’ll briefly introduce some examples.

HTML
<!--[if IE]>
	<link rel="stylesheet" type="text/css" href="ie.css">
<![endif]-->
CSS
/* For IE6 only */
*html .element {
	color: red;
}

/* For IE7 only */
*+html .element {
	color: blue;
}
JavaScript
if (typeof Object.create !== "function") {
	Object.create = function (proto) {
		function F() {}
		F.prototype = proto;
		return new F();
	};
}

The following are examples using prefixes enclosed by hyphens.

CSS
.element {
	-webkit-transition: all 0.3s;
	-moz-transition: all 0.3s;
	-ms-transition: all 0.3s;
	transition: all 0.3s;
}

Next is an example of JavaScript library (jQuery) code.

JavaScript
if ($.browser.msie && parseInt($.browser.version) <= 8) {
	// Special handling for older Internet Explorer versions (IE8 and below)
	$('body').addClass('ie8-fix');
}

In browsers, you can force recognition by appending code right before display. That said, fine-tuning support is endless, so generally only the latest browsers are targeted. In reality, the correct approach is to keep writing detailed handling as time permits.

For any project, a commitment to meticulous craftsmanship may be crucial.

Leave a comment on the article