简体   繁体   中英

Disable HTML content for IE users

I'm wanting to create (or use existing) code that will disable a pages content for IE users.

This HTML page should only be available to Google Chrome and Firefox users.

Any ideas on where I should start at, or if you know of any code like this that already exists? I'm a novice to programming and need a headstart, but I'm willing to program my own code if someone can push me in the right direction.

Try adding this to your head section:

<!--[if IE]>
    <link rel="stylesheet" type="text/css" href="ie-styles.css" />
<![endif]-->

Then in that stylesheet make it:

body {
display: none;
}

Additionally, add the following code to your <head> to ensure that later versions of IE will read the conditional comments.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">

You can try with jQuery

$(document).ready(function({
   jQuery.each( jQuery.browser, function( i, val ) {
         if ( $.browser.webkit || $.browser.mozilla ) {
           alert( "Render HTML!" );
         }
   });
}));

Or with PHP function get_browser() http://www.php.net/get_browser

Without the CSS or JavaScript, I guess this is the best solution.

<!--[if !IE]-->
    <body>
        ...
        ...
        ...
    </body>
<!--[endif]-->

Surround the <body> tags with IF !IE conditional comments.

If you can use .htaccess on your server, you can use this server-side (redirection) method.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*MSIE.*$ [NC]
RewriteRule .* ie.php
# RewriteRule .* http://www.example.com/ie.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM