1

I need to run a script that will disable a another script on the page. How do I do this?

(Internet Explorer Issues is why I am having to do this.) I am using jQuery 1.8.

Please provide examples.

8
  • you can remove the script tag of the script you dont want to run by javascript Commented Aug 19, 2012 at 8:53
  • 2
    What have you tried so far? What are the Internet Explorer issues you are encountering? Are these scripts all on a page you have created yourself? Commented Aug 19, 2012 at 8:55
  • @RichardEv - Nothing because I do not know where to start and JS is not my strong suit. I attempted to use conditional comments for my issue but those are not working correctly. Commented Aug 19, 2012 at 8:57
  • If you show us the conditional comments approach you have tried, it will tell us a little more about the problem you are having. This will hopefully help us help you. Commented Aug 19, 2012 at 8:59
  • @Lynda I think you might be complicating things too much. I answered your other question. I believe that's what you need to fix IE. Try to work with that, you don't need multiple scripts if you do it that way. Like I showed you can just use if (isIE8) within your code when you need it. Commented Aug 19, 2012 at 9:00

3 Answers 3

3

Using jQuery you can test for IE and then load the script if it returns true.

jQuery.browser might be moved to a plugin later, if it breaks when you update your library start looking into it first.

Keep in mind that it is usually not advisable to test for a specific browser, better to test for features the browser can work with. Sometimes you don't have a choice:

if(jQuery.browser.msie)
{
    $.getScript("lynda-ie.js");
}

If you need a script for a specific version if IE you can also test for its version :

if(jQuery.browser.msie)
{
    switch (parseInt(jQuery.browser.version,10))
    {
        case 6 :
            $.getScript("lynda-ie-6.js");
        break;
        case 7 :
            $.getScript("lynda-ie-7.js");
        break;
        case 8 : case 9 : default :
            $.getScript("lynda-ie.js");
        break;
}
Sign up to request clarification or add additional context in comments.

2 Comments

It is, but it still works with jQuery 1.8. That's why I mentioned the library update issue.
Added a test for specific versions if you need to.
0

Why don't you use a flag ?

If this flag is "1" ( for example) the code will run

otherwise , it won't.

1 Comment

Can you provide an example? JS is not my strong suit.
0

A "nicer" way to conditionally attach scripts depending on whether a browser is IE or not is to use "conditional comments". These are available in IE5+ but are compatible with all browsers because of how they are designed. They allow you to set certain parts of your HTML as being intended for for IE only, or for all non-IE browsers, or all browsers (IE and non-IE).

Example:

<!--[if IE 8]>
<script src="internet-explorer.js"></script>
<![endif]-->

<![if !IE]>
<script src="not-internet-explorer.js"></script>
<![endif]>

<script src="all-browsers.js"></script>

Link: http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx

1 Comment

That is what I originally attempted but for some reason it was not working correctly.

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.