Skip to content

Instantly share code, notes, and snippets.

@oogatta
Last active June 3, 2023 11:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oogatta/7208821 to your computer and use it in GitHub Desktop.
Save oogatta/7208821 to your computer and use it in GitHub Desktop.
Strange behavior of the IE11 on compat-mode. A function wrapping 'typeof' mis-detect an ActiveXObject.
<!DOCTYPE html>
<html>
<head>
<script src="test.js"></script>
</head>
<body>
</body>
</html>
location /ie11-emulateie7/ {
alias /home/oogatta/ie11/;
add_header 'X-UA-Compatible' 'IE=EmulateIE7';
expires epoch;
add_header Cache-Control private;
add_header Cache-Control must-revalidate;
add_header Cache-Control no-store;
add_header Pragma no-cache;
}
location /ie11-emulateie8/ {
alias /home/oogatta/ie11/;
add_header 'X-UA-Compatible' 'IE=EmulateIE8';
expires epoch;
add_header Cache-Control private;
add_header Cache-Control must-revalidate;
add_header Cache-Control no-store;
add_header Pragma no-cache;
}
location /ie11-emulateie9/ {
alias /home/oogatta/ie11/;
add_header 'X-UA-Compatible' 'IE=EmulateIE9';
expires epoch;
add_header Cache-Control private;
add_header Cache-Control must-revalidate;
add_header Cache-Control no-store;
add_header Pragma no-cache;
}
location /ie11-emulateie10/ {
alias /home/oogatta/ie11/;
add_header 'X-UA-Compatible' 'IE=EmulateIE10';
expires epoch;
add_header Cache-Control private;
add_header Cache-Control must-revalidate;
add_header Cache-Control no-store;
add_header Pragma no-cache;
}
location /ie11-edge/ {
alias /home/oogatta/ie11/;
add_header 'X-UA-Compatible' 'IE=edge';
expires epoch;
add_header Cache-Control private;
add_header Cache-Control must-revalidate;
add_header Cache-Control no-store;
add_header Pragma no-cache;
}
var isFunction = function(object) {
// only with 'typeof'
return typeof object == 'function';
};
// run in one thread. piled up karma
var result = '';
for ( var i=1; i<12; i++ ) { // the number varies. I'm not sure why. It might be the defference between 32bit and 64bit, or among zones, or something
result += isFunction() + '\n';
}
// then check in another thread, bang.
setTimeout(function(){
var dom = document.getElementsByTagName('body')[0];
alert(isFunction(dom)); // true!, ActiveXObject
alert(result); // all false
alert(isFunction(XMLHttpRequest)); // true, another ActiveXObject
// NOTICE: the type of XMLHttpRequest is 'function' on standard-mode, 'object' on emulateIE7 & emulateIE8 mode
alert(isFunction({})); // false, pure JS Object
},0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment