4

I am using ruby on rails 3 for my site and am almost finished, the site is due to go live very soon (Monday) but I am having problems with IE7 compatability, so as a temporary measure I would like to have users redirected to a "404" esque page if they are using IE7, it will just have some basic info stating to try another browser for now until the issues are fixed

How would i go about this in rails 3? Has anyone done anything like this in the past? I dont want to get into the should I/shouldnt I support IE7, I am going to, just going to take a little longer than I thought

Any help on this appreciated

Josh Unger
  • 6,717
  • 6
  • 33
  • 55
Richlewis
  • 15,070
  • 37
  • 122
  • 283

4 Answers4

13

You could do a script to redirect:

<!--[if IE 7]>
  <script type="text/javascript">
    window.location = "http://www.google.com/";
  </script>
<![endif]-->

Or a html:

<!--[if IE 7]>
  <meta http-equiv="REFRESH" content="0;url=http://www.google.com/">
<![endif]-->

Or simply leave a message saying that this site don't support

waldyr.ar
  • 14,424
  • 6
  • 33
  • 64
2

If you are able to use jQuery, you can do a simple browser version test and then redirect to the appropriate page and set a cookie:

   //IE 7 browser detection
    if ($.browser.msie) {
        var version = $.browser.version;

        if (version == '7.0') {
            var cookie = $.cookie('IE7');

            if (cookie != 'set') {
                $.cookie('IE7', 'set');

                window.location = '404-url-string';

            }

            window.location = '404-url-string';

        }
    }

you will need to bring in the jquery cookie plugin as well to set the cookie. The '404-url-string' would be the pathname of the page you are directing to.

DOCbrand
  • 339
  • 1
  • 6
1

As a temporary measure, would a IE conditional with a Javascript redirect work?

  <!--[if IE 7]>
    <script type="text/javascript">
      window.location = "/upgrade_browser.html";
    </script>
 <![endif]-->

Source: Javascript redirect for Internet Explorer browser version user agent?

Community
  • 1
  • 1
  • would this go in my app/layouts file like the rest of my stylesheets/javascripts? thanks for your answer by the way – Richlewis Jul 19 '12 at 14:29
  • Not a problem. No, this would go in your application.html.erb file. The main if loop only shows for IE browsers, so you could practically place it anywhere in the file, but I would advise to place it before the `

    ` tag.

    –  Jul 19 '12 at 14:33
  • Not a problem. Make sure to change the window.location path to the page you would like it to redirect to. –  Jul 19 '12 at 14:34
  • ok so i have placed the above code in application.html.erb file and its all commented out (due to the – Richlewis Jul 19 '12 at 18:15
  • Are you using Internet Explorer 7, or use FF/Chrome and change your User agent? Don't worry about it. –  Jul 19 '12 at 18:34
  • apologies for asking again but any ideas on this one – Richlewis Jul 20 '12 at 13:54
  • Try using something like this: ` –  Jul 20 '12 at 19:13
  • Much better, all working, thank you so much. Any particular reason why that worked and the if statement for just ie7 didnt? Just curious – Richlewis Jul 20 '12 at 21:52
  • I'm not exactly sure. Are you sure you're using IE7 and not IEE6 (just checking)? –  Jul 21 '12 at 04:34
1

Little bit of javascript should take care of this one.

Here's a little demo of the JavaScript navigator object:

<script type="text/javascript">

txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";

document.getElementById("example").innerHTML=txt;

</script>

Note that this is literally taken straight from W3Schools (which I normally do not recommend, but for this issue it's fine)

Anyway, you're gonna want something like:

<script type="text/javascript">
if(navigator.appName=="Internet Explorer" && navigator.appVersion == "7.0.Whatever") //maybe its "IE", I didn't actually check. Sorry lol, don't have time to test this out
{
    window.location.href = "YourErrorPageFileName";
}
</script>

Throw that code in your login page (or master page, whatever), and you should be good to go.

Side note: no idea why the code is formatting all dumb like that. Guess StackOverflow is parses slashes weirdly under certain conditions

Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67