Skip to content

Instantly share code, notes, and snippets.

@neilsarkar
Created February 2, 2012 03:26
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 neilsarkar/1721221 to your computer and use it in GitHub Desktop.
Save neilsarkar/1721221 to your computer and use it in GitHub Desktop.
Firefox 10 Crossdomain isArray bug
# /etc/hosts
127.0.0.1 example.com
127.0.0.1 api.example.com
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<body>
<script>
document.domain = "example.com"
</script>
<!-- Subdomains only. Everything works as expected if we use src="/xdreceiver.html" -->
<iframe name="xd" src="http://api.example.com/xdreceiver.html"></iframe>
<script>
// we have to wait for the iframe to be loaded on the page
setTimeout( function() {
//both alert false
alert(Array.isArray(window.xd.arr))
alert(Array.isArray(window.xd.JSON.parse("[]")))
Array.isArray = function(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
}
//both alert true
alert(Array.isArray(window.xd.arr))
alert(Array.isArray(window.xd.JSON.parse("[]")))
}, 200)
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
</head>
<body>
<script>
document.domain = "example.com"
window.arr = []
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment