SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation I need help cleaning up this script

    Please don't laugh at how bad I am at editing some simple script:
    Please combine the two!

    <!-- Load explorerfix.js if they are using explorer, and load maxiframe.js if they are using firefox... -->
    <script type="text/javascript"><!--
    var scriptStr = 'java/unknown.js';

    if (typeof document.attachEvent != 'undefined') scriptStr = 'java/explorerfix.js';

    if (typeof document.addEventListener != 'undefined') scriptStr = 'java/maxiframe.js';

    document.write('<scr'+'ipt type="text/javascript" src="'+scriptStr+'"></script>');
    /* Do not put any code here that relys on
    either of the three scripts mentioned above. */
    //-->
    </script>

    <!-- One of the above scripts will be loaded here -->

    <script type="text/javascript"><!--
    /* Now you can use code that depends on
    any of the three scripts mentioned previously. */

    //defined in one of the scripts (unkown.js, ie_compatible.js or ns_compatible.js)
    BrowserIndependent.attachListener(myElement, myFunct, true);

    //--></script>
    <!-- ///////////////////////// Here is where I had to do it a second time b/c I am an idiot, Java programmers help! //////////////////////////////// -->
    <!-- Load nothing if they are using explorer, and load firefix.js if they are using firefox... -->

    <script type="text/javascript"><!--
    var scriptStr1 = 'java/unknown.js';

    if (typeof document.attachEvent != 'undefined') scriptStr1 = ' ';

    if (typeof document.addEventListener != 'undefined') scriptStr1 = 'java/firefix.js';

    document.write('<scr'+'ipt type="text/javascript" src="'+scriptStr1+'"></script>');
    /* Do not put any code here that relys on
    either of the three scripts mentioned above. */
    //-->
    </script>

    <!-- One of the above scripts will be loaded here -->

    <script type="text/javascript"><!--
    /* Now you can use code that depends on
    any of the three scripts mentioned previously. */

    //defined in one of the scripts (unkown.js, ie_compatible.js or ns_compatible.js)
    BrowserIndependent.attachListener(myElement, myFunct, true);

    //--></script>

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,608
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    The following does what you wanted the first one to do. It loads one thing for IE and something else for all browsers except IE. It is just about impossible to tell the difference between browsers that are not IE and so Mozilla, Netscape, Opera, Safari, Konqueror etc will run the same code as for your Firefox version. Note that it doesn't require Javascript to distinguish different scripts to load in this instance as it can be done entirely in HTML using IE proprietary conditional tags. There are also IE conditional tags available in JScript for those instances where you need to tell within the Javascript code whether it really is Javascript (run by all browsers except IE) or JScript (the IE equivalent).

    <!-- Load explorerfix.js if they are using explorer, and load maxiframe.js if they are using anything other than explorer... -->
    <!--[if IE]><script type="text" src="explorerfix.js"></script><![endif]-->
    <!--[if !IE]-->]><script type="text" src="maxiframe.js"></script><!--[endif]-->
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up sweet

    Cooooool, I tried <!--[if != IE]> before but that didn't work! I knew about the tag without the -not- but knowing how to do -not- is going to help me, no doubt. Thanks for this.

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <!--[if !IE]--><!--[endif]--> Doesn't seem to work =( It hides the <script type="text" src="xxxx"></script> from FF.

    Could someone use the script I gave before, that is working, and make it compact? All you have to do is have

    if (typeof document.addEventListener != 'undefined') scriptStr = 'java/maxiframe.js';

    load java/firefix.js as well as maxiframe.js!

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here, check out my site:

    With my origional browser filter: http://rentev.com/leoj/leojcorp/FF3.html

    With your new browser filter: http://rentev.com/leoj/leojcorp/FF.html

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OMG, would you look at that! It is now working with your provided "not IE" script. I had set the type="text"... Just realized my mistake when I looked at the post I made 2 posts ago. Thanks for the awesome "IE/win hack"! But I would still like to use my original script, because I think it is more secure. I read that a lot of browsers can read through the if IE comment, and FF can be set to do this...

    No rush, I have 2 functioning scripts now. I would just like the original one to take up less room, lol.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •