2

So I have a popup that opens from my home page through a "?" link. I wan run one script (Help.htm) to run if the user is using chrome, FF, Opera etc and a second script (Help_IE.htm) to run if the user is using IE.

js

 <script type="text/javascript">
            function popup() {
                window.open("Help.htm", "Help", "scrollbar=yes,location=yes,width=500,height=420");
            }
        </script>

html

    <a href="javascript:popup()">?</a>

I want to be able to interchange the JS scripts depending on the browser using conditional comments or if anyone has a more efficient answer, i'm open to anything, Thanks.

Attempt

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
<!--[if IE]>
    <script type="text/javascript">
    function popup() {
        window.open("Help_IE.htm", "Help", "scrollbar=yes,location=yes,width=500,height=420");
    }
    </script>
<![endif]-->

<script type="text/javascript">
    function popup() {
        window.open("Help.htm", "Help", "scrollbar=yes,location=yes,width=500,height=420");
    }
</script>
luke-sully
  • 303
  • 5
  • 16
  • can you show what you've tried so it's not suggested again? can you explain why you need different files? – atmd May 07 '15 at 11:01
  • @atmd For a project, I need to retrieve browser detection details(version, useragent etc) but IE has caused me so much hassle so I decided to create a separate script which runs perfectly now. – luke-sully May 07 '15 at 11:10
  • 1
    Check this [POST](http://stackoverflow.com/questions/3387827/how-to-call-browser-based-css]) – Raghava Rudrakanth P V May 07 '15 at 11:18

2 Answers2

1

You can use conditional if in function if you knew how to query a variable with the browser you're using ( and to do this you could go with something like modernizer) ;

but in your situation you could also try wrapping your script in html conditionals (like you'd do with CSS - it should work);

for ex. IE:

 <!--[if IE]>
 <script type="text/javascript">
        function popup() {
            window.open("Help.htm", "Help", "scrollbar=yes,location=yes,width=500,height=420");
        }
       </script>
  <![endif]-->

for non IE:

 <!--[if !IE]>
 <script type="text/javascript">
        function popup() {
            window.open("Help.htm", "Help", "scrollbar=yes,location=yes,width=500,height=420");
        }
     </script>
 <![endif]-->
maioman
  • 18,154
  • 4
  • 36
  • 42
0

You can use conditional comments if you want. Alternatively, check this answer https://stackoverflow.com/a/13480430/1410583

Community
  • 1
  • 1
Faiz Shukri
  • 95
  • 10
  • I already have the browser detection scripts running with the specs i was given so i'm gonna go the CC route, thanks – luke-sully May 07 '15 at 11:16