Skip to content

Instantly share code, notes, and snippets.

@cou929
Created July 31, 2013 06:24
Show Gist options
  • Save cou929/6119775 to your computer and use it in GitHub Desktop.
Save cou929/6119775 to your computer and use it in GitHub Desktop.
以下の html に "hash_sample.html#foobar" というように hash 付きでアクセスする。IE 系は location.hash が取れないがそれ以外のブラウザだととれる。また document.write した script から見えている window.location はもとの 'hash_sample.html' である。
<html>
<body>
<script>
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var iframe_doc = iframe.contentWindow.document;
iframe_doc.write('<html><body><sc' + 'ript>alert(window.location.hash)</sc' + 'ript></body></html>');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment