Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE Version checking not working 1

Status
Not open for further replies.

pahiker

Programmer
Aug 31, 2012
45
US
The code below is to test for IE7 or 8 to inform the viewer of incompatibility, but it doesn't work. The first alert does show 7 or 8, but the second alert never displays, I have tried it as 7.0 and just 7.

Code:
function versionCheck() {
	var rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat(RegExp.$1);
	}
	alert (rv);
	if (rv == 7.0 || rv == 8.0)
		alert("Minimum browser requirement is IE9. Please consider updating your browser, or check back later.");
}

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Hi

That way the JavaScript will just compare what it received. And the browsers can be instructed to show anything the user want as browser name and version.

Beside that, why not showing the alert to Explorer 6 users ?

Anyway, why an [tt]alert()[/tt] ? And why JavaScript ? Personally I have a regular paragraph on my site, inside a conditional comment block. Something like this :
HTML:
[gray]<!--[if lt IE 9]>[/gray]
[gray]<p>Minimum browser requirement is IE9. Please consider updating your browser, or check back later.</p>[/gray]
[gray]<![endif]-->[/gray]

Regarding your code, it should work. What are you getting for [tt]alert[teal]([/teal]rv [teal]==[/teal] [purple]7[/purple] [teal]||[/teal] rv [teal]==[/teal] [purple]8[/purple][teal])[/teal][/tt] ? ( And why not simply [tt]alert[teal]([/teal]rv [teal]<[/teal] [purple]9[/purple][teal])[/teal][/tt] ? )


Feherke.
[link feherke.github.com/][/url]
 
Both alerts work for me. In IE7 and IE8. They show up correctly.

If the second alert is not showing up it may be because the rv value is neither 7.0 nor 8.0.

With that said however, I'm with feherke in that a conditional block would be far better and easier to implement and maintain.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
Thank you both.

The reason I did not use the conditional check is one of the most brilliant of all reasons - didn't know about it. I did search here for methods of checking for the IE version before posting, and this did not come up in any of my results.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Actually, now I remember why I need the checks. I have a work-around for 7&8, so I need, in JS, to know if I am working with either of these two versions.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Okay, I added the alert(rv==7 || rv==8) and I'm not getting an alert window at all. I do get the window as false in IE9 & 10.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Hi

pahiker said:
Okay, I added the alert(rv==7 || rv==8) and I'm not getting an alert window at all. I do get the window as false in IE9 & 10.
Weird. Maybe the float point arithmetic's peculiarity ? Try this condition [tt]alert[teal]([/teal]Math[teal].[/teal]floor[teal]([/teal]rv[teal])==[/teal][purple]7[/purple] [teal]||[/teal] Math[teal].[/teal]floor[teal]([/teal]rv[teal])==[/teal][purple]8[/purple][teal])[/teal][/tt]. Or the previous one, but use [tt]parseInt()[/tt] instead of [tt]parseFloat()[/tt] when assigning the value to rv.

But anyway, this not explains the no window at all thing. We may need to see the entire page where this behavior is manifested.

Regarding strictly checking for Explorer 7 and 8, conditional comments' expression can express that :
HTML:
[gray]<!--[if (IE 7)|(IE 8)]>[/gray]
[gray]<p>Minimum browser requirement is IE9. Please consider updating your browser, or check back later.</p>[/gray]
[gray]<![endif]-->[/gray]

Feherke.
[link feherke.github.com/][/url]
 
Correct me if I am wron but would it not be possible to use the conditional block to set a Javascript flag for work around?

somtheing like (crude & untested)
Code:
<!--[if (IE 7)|(IE 8)]>
<script> Flag='True';</script>
<![endif]-->

A Maintenance contract is essential, not a Luxury.
Do things on the cheap & it will cost you dear
 
Weird. Maybe the float point arithmetic's peculiarity ? Try this condition alert(Math.floor(rv)==7 || Math.floor(rv)==8). Or the previous one, but use parseInt() instead of parseFloat() when assigning the value to rv.

But anyway, this not explains the no window at all thing. We may need to see the entire page where this behavior is manifested.

Putting in your change did not work, but it led me to discover why it didn't work, and what my problems has been, the question now is: how do I resolve the "problem"?

I am testing with three browsers - IE7 under XP, Safari on XP and Mac (also using BrowserShots.org). What I discovered, after inserting your changes and not having them work, is that both XP browsers are working with old pages. I can't seem to get them to reload the new JavaScripts, or the new index.html page. I have clear the cache/browser history, even done a full reset on Safari, each time the page loads and the alert window shows "Made it!" -- the problem is, I removed that alert late last night!

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Are you sure you are pointing it to the right file? Are you developing this locally, and then uploading? If so are you sure the upload is correctly completed?

Sounds like the file being pulled by the browser is not the one you are editing.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
I am editing it through GoDaddy's online editor, right now I do not have access to my usual editor.

If I look at the first few lines in the function that sets the text and number of buttons this is what I see:


In GoDaddy's editor:
Code:
function setButton(chapter) {
alert("setButton");

	var mie = "Microsoft Internet Explorer";
	if (navigator.appName == "Microsoft Internet Explorer") {
		alert("matched");
		var rv = -1;
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

		if (re.exec(ua) != null)	rv = parseFloat(RegExp.$1);
		if (rv == 7 || rv == 8)		alert(rv == 7 || rv == 8);
	}


	var ary = new Array();

So I should see the alert window "setButton", but I don't (this function is called when the page is first loaded).


If I load the script from IE7 ( I see:
Code:
function setButton(chapter) {
	var ary = new Array();

	switch (chapter) {

Which resembles what IE7 is actually doing.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
I get the correct file it seems from the link:

Code:
function setButton(chapter) {
alert("setButton");

	var mie = "Microsoft Internet Explorer";
	if (navigator.appName == "Microsoft Internet Explorer") {
		alert("matched");
		var rv = -1;
		var ua = navigator.userAgent;
...


I guess you could try to find the js file in IE's temporary internet files and remove it and see if that gets it to download the newer version.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech
 
I've tried clearing it from within IE, no luck. I'm not familiar enough with MS file structures to know where the cache files are located. I've tried searching for "temp" and "internet" with no luck, searching for "cache" returns dozens of folders and files, none seem aptly named.

I'm beginning to wonder if it is the company I am contracting at, perhaps their firewall is caching the files.

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Apparently I was right, it took a couple hours, but the script does reflect what is up on the server.

One question, when I click on one of the three buttons on the top of the site it modifies the lower buttons. I know this is working in IE7 because I can see the verbiage in the buttons change. But, clicking on the buttons does not launch the JS to load the pages (I have an alert set as soon as it goes into that script, and it does not pop up). When I look at the source after the buttons have been changed it reflects the original source of the page. Does this mean the script that changes the buttons didn't fully work, or does the source that IE shows not reflect the modified page? If the latter, is there some way to see the modified page?

Let all bear in mind that a society is judged not so much by the standards attained by its more affluent and privileged members as by the quality of life which it is able to assure for its weakest members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top