User Agent is not a reliable method.
Personally I use an Agent Switcher to fool websites quite often.
This method would not be fooled.
My only option would be to disable JavaScript.
Pick a JS instruction that works in IE9+ and not previous versions
There is probably a better instruction to use other than getElementsByClassName
but it demonstrates the concept.
Pick an instruction form a test page like this:
Browser Capability Tests
Then build a test page and test that page on a Cross Browser Test site.
This test will properly pass (TRUE) or fail (FALSE) based on Browser support for try{}catch{}
on any Browser going back to 1999:
- Netscape 6.0
- FireFox 1.0
- IE 5.5
It will Pass TRUE on:
- Chrome
- FireFox 3.0+
- IE9+
- Opera
- Safari
Will fail (FALSE) only on IE5.5 - IE8
HTML
<div class="test"></div>
JS
var checkIE = false;
try {
var el = document.getElementsByClassName('test');
checkIE9 = true;
}
catch(e) {
checkIE9 = false;
}
Then redirect based whether checkIE9 is true or false
Replace mozilla.org with the IE9 page/script and microsoft.com with the old style page/script
if (checkIE9){
window.location = 'http://mozilla.org';
}
else{
window.location = 'http://www.microsoft.com';
}
Or submit a form based on true or false.
HTML
<form action="true.php" method="get"><div>
<input type="hidden" name="chkIE" value="1"/>
<button id="t" type="submit"></button>
</div></form>
<form action="false.php" method="get"><div>
<input type="hidden" name="chkIE" value="2"/>
<button id="f" type="submit"></button>
</div></form>
NOTE: Yes it could be one form with two buttons but forms are cheap, and I like to pass values with hidden inputs.
I did not use zero as a value in case the a user were to go direct to the page the forms link to.
Zero Check Code in the test.php:
$chckIE9 = intval($_GET['chkIE9']);
if($chckIE9 == 0){
include('test.html');
exit;
}
Or if you may want an intermediate page and link both true and false to the same script.
<form action="test.php" method="get"><div>
<input type="hidden" name="chkIE" value="1"/>
<button id="t" type="submit"></button>
</div></form>
<form action="test.php" method="get"><div>
<input type="hidden" name="chkIE" value="2"/>
<button id="f" type="submit"></button>
</div></form>
PHP:
$chckIE9 = intval($_GET['chkIE9']);
if($chckIE9 == 1){
include('true.php');
}
elseif($chckIE9 == 2){
include('false.php');
}
else{
include('test.html');
}
exit;
JS
Here a decision must be made as to which way to default.
You could click 'f' if (!checkIE9)
Then default would be the IE9+
If there is a need to default it is probably better to default to the false
if (checkIE9){
document.getElementById('t').click();
}
else{
document.getElementById('f').click();
}
Snipppet
This snippet will display either "IE9+ Compatible" or "UPDATE YOUR BROWSER"
This code is tested with IE8 which pops up "UPDATE YOUR BROWSER"
var checkIE = false;
try {
var el = document.getElementsByClassName('true');
checkIE9 = true;
}
catch(e) {
checkIE9 = false;
}
if (checkIE9){
document.getElementById('t').style.display = 'block';
}
else{
document.getElementById('f').style.display = 'block';
}
#t,#f,.hide{display:none;}
<!DOCTYPE html>
<html lang="en">
<head></head><body>
<div id="t" class="true"><h2> IE9+ Compatible</h2></div>
<div id="f"><h2> UPDATE YOUR BROWSER</h2></div>
</div>
<form action="test.php" method="get"><div><input type="hidden" name="chkIE" value="1"/><button class="hide" id="t" type="submit"></button></div></form>
<form action="test.php" method="get"><div><input type="hidden" name="chkIE" value="2"/><button class="hide" id="f" type="submit"></button></div></form>
</body></html>