Need script to detect browser then do an action

Discussion in 'JavaScript' started by theredgiant, Feb 24, 2008.

  1. #1
    My site breaks in IE6 but works well with IE7. I need a javascript that will check if any visitor is using IE6 then display a message. I'm a completely noob in programming so please don't refer me to site that teach you to do it. I need a ready made script. The script will be uploaded to the server and a code between <script> tags will be placed on the page.

    I plan to put the message in a widget that will displayed at the top of the article. The widget should run only when the browser is IE6.

    Please help me.
     
    theredgiant, Feb 24, 2008 IP
  2. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this

    <script type="text/javascript">
    if (document.all && !window.opera) { // IE browser
    if (window.XMLHttpRequest) {
    alert('IE7');
    }
    else {
    alert('IE6 or lower');
    }
    }
    </script>
     
    sharry, Feb 24, 2008 IP
  3. theredgiant

    theredgiant Well-Known Member

    Messages:
    722
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Instead of the alert box, can't we just display a text in the body of the page?
     
    theredgiant, Feb 24, 2008 IP
  4. dancom96

    dancom96 Well-Known Member

    Messages:
    1,556
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    105
    #4
    Why don't you use one that doesn't use javascript at all?
    <!--[if IE 6]>
    Put the message for IE6 users here
    <![endif]-->
     
    dancom96, Feb 24, 2008 IP
  5. theredgiant

    theredgiant Well-Known Member

    Messages:
    722
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #5
    @dancom96: I want the message to be seen only by ie6 users. How to do that without javascript? I want the code. Sorry, for beign so dumb.
     
    theredgiant, Feb 24, 2008 IP
  6. theredgiant

    theredgiant Well-Known Member

    Messages:
    722
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #6
    Ok. I got it. Thanks.
     
    theredgiant, Feb 24, 2008 IP