Search code examples
internet-explorerjsfconditional-comments

How to ban Internet Explorer?


I try to ban the Internet Explorer by a meta tag in my template.

template.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view locale="de_DE">
<h:head>
    <f:facet name="first">
        <h:outputText
            value="&lt;!--[if IE]&gt;
        &lt;h1&gt;No IE support.&lt;/h1&gt;
        &lt;![endif]--&gt;"
            escape="false" />
    </f:facet>
...

In that way it doesn't work. How can I achieve it?


Solution

  • What you've there is not a meta tag, but just an IE conditional comment which conditionally shows a piece of HTML code depending on whether the enduser is using IE or not. To present a piece of HTML code in the page body, you have to put the HTML code in the <body>, not in the <head>.

    <h:body>
        ...
        <h:outputText
            value="&lt;!--[if IE]&gt;
        &lt;h1&gt;No IE support.&lt;/h1&gt;
        &lt;![endif]--&gt;"
            escape="false" />
        ...
    </h:body>
    

    Note that this doesn't magically hide the remainder of the page in any way. You'd have to expand this by including a CSS <link> which contains something like #content { display: none; }.


    Unrelated to the concrete problem, as you're based on your question history already using OmniFaces, you may find the <o:conditionalComment> helpful to render IE conditional comments in a developer friendly way in JSF.

    <h:body>
        ...
        <o:conditionalComment if="IE">
            <h1>No IE support.</h1>
        </o:conditionalComment>
        ...
    </h:body>