0

Sorry for the title ,it is indeed confusing.

I have some javascript code that works in every browser except IE 7 and 8 (it throws errors). So as a work around I would like the code not to run on certaing pages of all browsers where its redundant.

I would like the solution to be in javascript because I only want to disable in some pages instead of apply the rule to all.

HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87
  • Wrap around with an if (browser = this and that) {...} ? – Lajos Veres Oct 24 '13 at 07:50
  • is this static pages or do you have some kind of server side code i.e. php or ruby? if there is server side code, wouldn't be better to sniff the user-agent and render the page accordingly? – booyaa Oct 24 '13 at 07:54
  • @LajosVeres:the thing is i have a common js include on every page which consist of all the js scripts including the one that gives me error.Only for IE I want to disable this script.Is it possible. – HIRA THAKUR Oct 24 '13 at 07:54
  • If it just needs to be blocked for is, use conditional comments : `` – Anthony Oct 24 '13 at 08:01

5 Answers5

0

I think for example this function can help you to skip the javascripts on javascript side:

http://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx

Or you can do this on php side also:

PHP: If internet explorer 6, 7, 8 , or 9

Community
  • 1
  • 1
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
  • thx for the answer..but i dont want to detect the browser..its just some..lets say if there is a script that i just want to stop it to execute...thats my real question. – HIRA THAKUR Oct 24 '13 at 07:59
0

You can use IE conditional statements in the head tag to include JS only when the browser is IE of a specific version:

<!--[if lt IE 8]>
<script src="myscript.js" type="text/javascript"></script>
<![endif]-->

The code is wrapped in a comment statement on purpose!

http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx

user1107799
  • 272
  • 2
  • 13
0

I really don't understand you question well. But if you want disable the script of IE

You can try this(for example):

For disabline script for IE -

 <!--[if !IE]><!-->
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script>
            // your inline script goes here
    </script>
    <!--<![endif]-->

Read this 1

For disabling script for IE 8 -

<!--[if !(IE 8)]><!-->
    <script src="path/to/external/script"></script>
    <script>
        // your inline script goes here
    </script>
<!--<![endif]-->

and

<!--[if !(gte IE 8)]><!-->
    <script src="path/to/external/script"></script>
    <script>
        // your inline script goes here
    </script>
<!--<![endif]-->

Read this 2

Removing a Script block :

set a id to your script,

 <script id="sample">
    ...
    </script>

and use this code,

 $("#sample").remove();
Community
  • 1
  • 1
Ishan Jain
  • 8,063
  • 9
  • 48
  • 75
0
<![if !IE]>
<script src="script.js"></script>
<![endif]>
Udit Bhardwaj
  • 1,761
  • 1
  • 19
  • 29
-1

I guess what you're looking for is document.location in combination with a browser detectio. But be aware that most browsers can fake the instances. If you're using jQuery I'd suggest you use the $.support property instead of trying to get the user agent.

http://api.jquery.com/jQuery.support/

Greetings

Niveaulos

Ophidian
  • 607
  • 7
  • 9