Skip to content

Instantly share code, notes, and snippets.

@nanto
Created November 9, 2014 09:08
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 nanto/695cfa663c066077e2ea to your computer and use it in GitHub Desktop.
Save nanto/695cfa663c066077e2ea to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>host of cloned 'a' element</title>
</head>
<body>
<script>
var a = document.createElement('a');
a.href = '';
a = a.cloneNode(false);
document.write('<p>a.host: ' + a.host + '<\/p>');
document.write('<p>location.host: ' + location.host + '<\/p>');
</script>
</body>
</html>
@nanto
Copy link
Author

nanto commented Nov 9, 2014

Open console and run the following code in any page.

var iframe = document.createElement('iframe');
iframe.src = 'http://bl.ocks.org/nanto/raw/695cfa663c066077e2ea/';
document.body.appendChild(iframe);

We expect a.host to be 'bl.ocks.org' but in IE it becomes a host of parent document.

@nanto
Copy link
Author

nanto commented Nov 9, 2014

This behavior of IE was referred to in http://d.hatena.ne.jp/monjudoh/20110207/1297071182 (written in Japanese).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment