I have a puzzling problem: this seemingly simple page doesn’t work in IE9:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<!-- jq.js is the non-minified jQuery library -->
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('body').append('<h1>ok</h1>');
});
</script>
</head>
<body>
</body>
</html>
The behaviour I get is that sometimes the page displays “ok”, and sometimes it doesn’t display anything. I have found out that it depends on how fast the computer is. If you’re on a fast computer, it usually works, but on slow computers, it fails around 2 out of 3 times.
When I look in the debugging console, the symptom is that jQuery gets a permission denied when trying to access navigator.userAgent.
The browser writes (in the log) that it is switching from quirks mode to IE9 mode. My hypothesis has been that jQuery is being loaded before the browser switches to IE9 mode, causing jQuery to be caught in the quirks mode and from there on unable to access any browser attributes.
I have tried inserting <!doctype html> and inserted the X-UA-Compatible meta tag to make IE9 switch to IE9 mode right away, but it didn’t fix the problem.
I have managed to leave out jQuery and reproduce the issue with this simple snippet:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
</head>
<body>
<script type="text/javascript">
document.write('<h1>testing</h1>');
try {
document.write('<h1>' + navigator.userAgent + '</h1>');
document.write('<h1>ok</h1>');
} catch(e) {
document.write('<h1>not ok</h1>');
}
</script>
</body>
</html>
(Available at http://test.m.e17.dk/ie9-navigator/.)
Reproduce it by:
- Open the page.
- Press F5.
- Place cursor in address bar.
- Press enter.
Repeat steps 2-4 as often as desired. Could the issue arise from not waiting for the DOM to load (as said in http://bugs.jquery.com/ticket/12282).
I have found the cause of this error: it was a group policy setting in Active Directory that caused IE9 to misbehave. I’ll try to get the exact name and add it here for anyone who’d encounter the same issue.
Thanks to everyone helping out.
The policy in question is in the attached picture below.