1

do you know of any way to prevent a script i have on a web page to be loaded by IE7 only?

The script works fine in all other browsers so I just wanted to disable it on IE7.

Is this at all possible?

Alex

4
  • 4
    Wouldn't it be smarter to make the script work in IE7 as well ? Show it to us and maybe we can help. Commented Feb 10, 2012 at 15:04
  • 1
    Does this mean that the script is working in IE6? Commented Feb 10, 2012 at 15:08
  • @DidierGhys you are right it's just that i wanted a quick n dirty solution fr the time being, and i would look into js later. i didnt write the js myself and it's difficult to pinpoint the issue Commented Feb 10, 2012 at 15:17
  • This is why you should never do quick&dirty... because you will simply never take care of the js later. I've worked on projects completely built upon quick&dirty solutions for this exact same reason. This is part if your job to make clients understand that resolving some bugs takes time and it is your responsability to keep a clean code base. Commented Feb 10, 2012 at 15:22

4 Answers 4

1
if(navigator.userAgent.indexOf('MSIE 7') < 0){
//do your non-IE7 stuff here
}

or even better

function DoSomStuff(){
  if(navigator.userAgent.indexOf('MSIE 7') > 0 ) return;
//do your non-IE7 stuff here
}
Sign up to request clarification or add additional context in comments.

2 Comments

I think this is the one :) I will try it out!
Please don’t use this! stackoverflow.com/a/9229864/96656 is a much more robust solution.
1

maybe this works for you:

<!––[if !IE 7]>
    <script type="text/javascript" src="different"></script>
    <![endif]––>

4 Comments

This will load the script if its IE7, whereas the OP is wanting to disable the script. You are missing your not operator.
Even with your edit, the whole thing will be recognized as a HTML comment by non-IE browsers.
yeah but he only wants to target IE7 so its fine
@EvilP: no, he wants to target not IE 7, which means IE 6, 8, 9, Chrome, Firefox, Safari, Opera, etc.
1

Yes there is, using conditional comments:

<!--[if !(IE 7)]>
<script>
    // Your script here
</script>
<![endif]-->

1 Comment

This won't load the script in non-IE browsers.
1

You can use down-level revealed conditional comments (with a bit of extra markup to satisfy validators):

<!--[if !(IE 7)]><!-->
    <script src="myscript.js"></script>
<!--<![endif]-->

However, any good web developer would recommend that you use feature detection instead of browser detection for your scripts. It's also possible that your IE 7 problem could be easily solved, so perhaps you might want to post it as a separate question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.