Browser detection sends IE7 into infinite loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Max58kl
    New Member
    • Nov 2007
    • 37

    Browser detection sends IE7 into infinite loop

    Hi
    I am trying to use browser detection to load browser specific
    web pages.
    The first part always seems to work ok, the Firefox page loads correctly.
    Everytime I try to load the page in IE7 rather than loading the page the
    browser goes into some kind of infinit loop

    Code:
    if(navigator.userAgent.indexOf("Firefox") != -1)
    {
       window.location = "ff_enquiries.html";
    }
    else if(navigator.userAgent.indexOf("MSIE") != -1)
    {
       window.location = "enquiries.html";
    }
    Can someone please help with this.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Instead of using browser detection and coding separate pages for each browser, how about coding for all browsers?

    Your code could probably be condensed into one with a bit of feature/object detection.

    Comment

    • mrhoo
      Contributor
      • Jun 2006
      • 428

      #3
      window.location = "enquiries.html ";
      Do you run this on a page with a file named "enquiries.html "?.

      Comment

      • Max58kl
        New Member
        • Nov 2007
        • 37

        #4
        Hi

        acoder - Thanks for the advice!

        mrhoo -

        I have a page called Contact that has a link to the enquiries page.
        I have created three enquires pages, one for IE one for Firefox and one for others.
        The plan is to link the Contact page to enquiries.html which contains the following code -

        [CODE=javascript]if(navigator.us erAgent.indexOf ("Internet Explorer") != -1)
        {
        window.location = "enquiries.html ";
        }
        else if(navigator.us erAgent.indexOf ("Firefox") != -1)
        {
        window.location = "ff_enquiries.h tml";
        }
        else
        {
        window.location = "other_enquirie s.html";
        }
        [/CODE]
        which will hopefully either load the page if IE or redirect to Firefox or Other

        Regards Max
        Last edited by acoder; Jun 3 '08, 02:03 PM. Reason: Added code tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Max58kl, what code do you have that doesn't work across all browsers? If you post it, we can look at changing it so that you can avoid this problem altogether. The userAgent is not reliable anyway and can be spoofed.

          PS. please post code using code tags. Thanks!

          Comment

          • Max58kl
            New Member
            • Nov 2007
            • 37

            #6
            Hi

            Sorry about the code tags!

            The enquiries page is a form with -

            13 text input fields
            1 text area
            2 radio buttons
            4 buttons
            1 check box
            1 submit button
            1 reset button,

            each field is enclosed in div tags and each field has label text enclosed in span tags,
            which is all probably too much to post on the forum, especially as I have created ids
            and classes for nearly every div and span tag (I don't have a great deal of experience with CSS).

            I think possibly the best way to go is for you to point me to some cross browser code for laying out forms.
            The current enquires.html page I made testing in IE7 which I eventually managed to get looking good,
            but when I looked at it in Firefox everything was distorted.
            I then duplicated the page and tweaked everything to get it to look good in Firefox.
            I then looked at both the IE7 and Firefox pages in IE6 and once again both pages were very distorted.
            So I duplicated the Firefox page because it was the best of the two and tweaked it to get it looking good in IE6.

            Your help is appreciated!

            Regads Max

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Since this is about laying out forms, I would suggest you start a new thread in the HTML/CSS forum. You can get it to work cross-browser using standard CSS code with possibly a few hacks to support IE. Make sure that IE is not in quirks mode by using a valid doctype. For more help, ask in the HTML forum.

              Comment

              • drhowarddrfine
                Recognized Expert Expert
                • Sep 2006
                • 7434

                #8
                Originally posted by Max58kl
                The current enquires.html page I made testing in IE7
                This is why your page looked wrong in other browsers. IE7 is 10 years behind web standards and wrong in its implementation. Never use IE7 as your test browser. Always use a modern browser like Firefox/Opera/Safari for your initial test. The bugs in IE are known, as are the hacks to fix it.

                Comment

                • Max58kl
                  New Member
                  • Nov 2007
                  • 37

                  #9
                  Hi

                  Once again thanks for the advice!
                  Hopefully HTML/ CSS can offer suggestions.

                  I will now do all initial testing in Firefox.

                  Thanks Max

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by Max58kl
                    The current enquires.html page I made testing in IE7 which I eventually managed to get looking good,
                    but when I looked at it in Firefox everything was distorted.
                    I then duplicated the page and tweaked everything to get it to look good in Firefox.
                    I then looked at both the IE7 and Firefox pages in IE6 and once again both pages were very distorted.
                    So I duplicated the Firefox page because it was the best of the two and tweaked it to get it looking good in IE6.
                    One other point to note is that there are not only three browsers (IE7, Firefox and IE6). Try to test on as many browsers and platforms as possible. You will find that if it works in, say Firefox or Opera, it will usually work in the rest more often than not (with the possible exception of IE, though that depends on how advanced the CSS used is).

                    Comment

                    Working...