Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathantneal/1332824 to your computer and use it in GitHub Desktop.
Save jonathantneal/1332824 to your computer and use it in GitHub Desktop.
get-that-blasted-button-type-in-ie8.html
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta charset="utf-8">
<title>GET THAT BLASTED BUTTON TYPE</title>
</head>
<body>
<button id="foo" class="a b c d=e"></button>
<button id="bar" type="submit"></button>
<script>
// Most elaborate work around ever
function getButtonType(btn) {
var
win = window,
doc = document,
i = 0,
allButtons = doc.getElementsByTagName('button'),
iframe = doc.createElement('iframe'),
xhr = new win.ActiveXObject('Microsoft.XMLHTTP'),
iframeDoc;
// hide iframe
iframe.style.display = 'none';
doc.appendChild(iframe);
// check index of button
while (allButtons[i] != btn) ++i;
// create ie7 iframe
iframeDoc = iframe.contentWindow.document;
iframeDoc.open();
iframeDoc.write('<!doctype html><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">');
iframeDoc.close();
// make xhr request
xhr.open('GET', win.location, true);
xhr.send(null);
// write to ie7 iframe
iframeDoc.body.innerHTML = xhr.responseText;
// check that button type
return iframeDoc.body.getElementsByTagName('button')[i].type;
}
// Get buttons
var btnA = document.getElementById('foo');
var btnB = document.getElementById('bar');
// Return button types
console.log(getButtonType(btnA));
console.log(getButtonType(btnB));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment