Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript/ Internet Explorer 9 issues

    I have the following script on a website:

    <script language="javascript">
    function toggle(targetId) {
    target = document.all(targetId);
    if (target.style.display == "none"){
    target.style.display="";
    } else {
    target.style.display="none";
    }
    }
    //-->
    </script>

    <font color="red" size="4" face="helvetica"><a href="javascript:toggle('Link1')"><font color="red">EXAMPLE</font></a>
    <div id="Link1" style="display: none"></font>

    <div align="left"><font color="#4a4a4a" size="2" face="helvetica">Example only. Example only. Example only.</font></div>
    </div>

    Code works fine on Internet explorer 6, chrome and opera. However, on internet explorer 9, it does not work. I have verified browser settings. Any help is appreciated. Thanks

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,589
    Thanks
    0
    Thanked 644 Times in 634 Posts
    document.all is for IE4 - for IE5 and later as well as all other modern browsers use document.getElementById
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by chasero13 View Post
    I have the following script on a website:
    Then lose it along with javascript:, language="javascript" and <font>, all of which are unnecessary or deprecated.

    Code:
    <script type="text/javascript">
    
    function toggle( targetId ) 
    {
      var elem = document.getElementById( targetId );
      
      elem.style.display = ( elem.style.display == "none" ? "block" : "none" ); 
      
      return false;
    }
    
    </script>
    
    <a href="#" onclick="return toggle('Link1')">EXAMPLE</a>
    <div id="Link1" style="display: none">
     <div align="left"><font color="#4a4a4a" size="2" face="helvetica">Example only. Example only. Example only.
     </div>
    </div>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,892
    Thanks
    202
    Thanked 2,528 Times in 2,506 Posts
    As I quite frequently say,

    The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that (as in this case) you are looking at ancient and perhaps unreliable code.

    Surely Chrome and Opera do not recognise document.all? That is IE specific.
    Last edited by Philip M; 11-07-2012 at 09:10 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    IE9 shouldn't recognize document.all() if the page validates...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    IE9 can *either* be standards compliant or older-IE-compliant.

    The best thing to do is simply forget that document.all *EVER* existed.

    It ceased to be needed when MSIE 5.0 arrived...in MARCH 1999.

    So are you REALLY going to worry about MSIE 4? A program made obsolete over THIRTEEN YEARS AGO???

    Sheesh.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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