Question

Are If statements available for html because I want this text to pop up when someone is using internet explorer <p>You are using Internet Explorer we don't support this browser</p>

And for firefox </p>Your browser is supported</p>

Is this possible?

HERE IS MY CODE:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My title</title>
<p class="accent">
<!--[if IE]>
According to the conditional comment this is IE<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is IE 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is IE 7<br />
<![endif]-->
<!--[if IE 8]>
According to the conditional comment this is IE 8<br />
<![endif]-->
<!--[if IE 9]>
According to the conditional comment this is IE 9<br />
<![endif]-->
<!--[if gte IE 8]>
According to the conditional comment this is IE 8 or higher<br />
<![endif]-->
<!--[if lt IE 9]>
According to the conditional comment this is IE lower than 9<br />
<![endif]-->
<!--[if lte IE 7]>
According to the conditional comment this is IE lower or equal to 7<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is IE greater than 6<br />
<![endif]-->
<!--[if !IE]> -->
According to the conditional comment this is <comment>not</comment> IE<br />
<!-- <![endif]-->
</p>
</head>
<body>
MY code here
</body>
</html>
Was it helpful?

Solution

There is no HTML if statement, but Internet Explorer has something called conditional comments. So you could say

<!--[if IE]>
<p>You are using Internet Explorer we don't support this browser</p>
<![endif]-->

<!--[if !IE]> -->
</p>Your browser is supported</p>
<!-- <![endif]-->

Although, the second part covers everything else, not only Firefox browser.

OTHER TIPS

Take a look at jQuery.browser: http://api.jquery.com/jQuery.browser/

The $.browser property provides information about the web browser that is accessing the page, as reported by the browser itself. It contains flags for each of the four most prevalent browser classes (Internet Explorer, Mozilla, Webkit, and Opera) as well as version information.

Available flags are:

webkit (as of jQuery 1.4) safari (deprecated) opera msie mozilla This property is available immediately. It is therefore safe to use it to determine whether or not to call $(document).ready(). The $.browser property is deprecated in jQuery 1.3, and its functionality may be moved to a team-supported plugin in a future release of jQuery.

Because $.browser uses navigator.userAgent to determine the platform, it is vulnerable to spoofing by the user or misrepresentation by the browser itself. It is always best to avoid browser-specific code entirely where possible. The $.support property is available for detection of support for particular features rather than relying on $.browser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top