Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-06-2012, 08:19 PM   PM User | #1
chasero13
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
chasero13 is an unknown quantity at this point
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
chasero13 is offline   Reply With Quote
Old 11-06-2012, 09:02 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,468
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 11-06-2012, 09:47 PM   PM User | #3
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 961
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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>
Logic Ali is offline   Reply With Quote
Old 11-07-2012, 08:11 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 11-07-2012 at 09:10 AM..
Philip M is offline   Reply With Quote
Old 11-07-2012, 11:55 PM   PM User | #5
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
IE9 shouldn't recognize document.all() if the page validates...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 11-08-2012, 12:24 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
internet explorer, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:49 AM.


Advertisement
Log in to turn off these ads.