JavaScript Works in IE 6, but not IE 7 - Example provided

G

Guest

Hi,

I have some simple JavaScript on my page that worked for years in IE 6
without an error that I am aware of, but does not work in IE 7. Any insight
on this issue that anyone can provide would be greatly appreciated.

Check out the example below in both browsers to see for yourself:
http://216.122.147.105/ie7error.html

NOTE: The above JavaScript functions properly in Netscape 8.n as well.
 
W

Walter Wang [MSFT]

Hi,

I think it's because the javascript function in your demo page isn't aware
of more recent IE versions. It's using the UserAgent string to check
browser type. On my system Windows XP SP2 with IE7, the UserAgent string is:

"mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; infopath.2; .net clr
2.0.50727; .net clr 3.0.04506.30; fdm; .net clr 1.1.4322)"

I think you might need to edit following script in function BrowserType():

this.ie = ((agt.indexOf("msie") != -1) && (! this.opera));
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")==-1)
&& (agt.indexOf("msie 6")==-1) && (agt.indexOf("msie 7")==-1));
this.ie4up = (this.ie && (this.major >= 4));
this.ie5 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")!=-1));
this.ie6 = (this.ie && (this.major == 4) && (agt.indexOf("msie 6")!=-1));
this.ie7 = (this.ie && (this.major == 4) && (agt.indexOf("msie 7")!=-1));
this.ie5up = (this.ie && !this.ie3 && !this.ie4);

However, I don't recommend it since it will easily break if IE 8 is out. I
recommend use following version of browser sniffer javascript:

#JavaScript Browser Sniffer: WebTools - WebReference.com
http://www.webreference.com/tools/browser/javascript.html



Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Laurent Bugnion

Hi,

However, I don't recommend it since it will easily break if IE 8 is out. I
recommend use following version of browser sniffer javascript:

#JavaScript Browser Sniffer: WebTools - WebReference.com
http://www.webreference.com/tools/browser/javascript.html

Browser sniffing can always be replaced by object detection, which is
clearly the way to go. Why would you want to remember (or hardcode)
which browser supports which functionality? Just test for it, and act
accordingly.

Example:

var nTextField = null;

if ( document.getElementById )
{
nTextField = document.getElementById( "myTextField" );
}
else
{
if ( document.forms
&& document.forms[ "myForm" ]
&& document.forms[ "myForm" ][ "myTextField" ] )
{
nTextField = document.forms[ "myForm" ][ "myTextField" ];
}
else
{
if ( document.all )
{
nTextField = document.all[ "myTextField" ];
}
}
}

if ( nTextField )
{
// Proceed
}

HTH,
Laurent
 
W

Walter Wang [MSFT]

Laurent,

Thanks for your input.

I agree that object detection is better and should be used if possible.

#JavaScript - Browser detect
http://www.quirksmode.org/js/detect.html

#Javascript - Object detection
http://www.quirksmode.org/js/support.html


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

This is an excellent apporach that I wasn't aware of. Thanks for the advice
and resources guys!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top