Skip to content

Instantly share code, notes, and snippets.

@timdorr
Created November 8, 2017 04:08
Show Gist options
  • Save timdorr/326ed608a9cbe67f247c2fbc709cdba3 to your computer and use it in GitHub Desktop.
Save timdorr/326ed608a9cbe67f247c2fbc709cdba3 to your computer and use it in GitHub Desktop.
isPlainObject iframe test case
<!DOCTYPE html>
<html>
<body>
<script>
function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null) return false
let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}
return Object.getPrototypeOf(obj) === proto
}
const iframe = document.createElement("iframe")
document.body.appendChild(iframe)
var doc = iframe.contentDocument
doc.open()
// doc.write("<body onload='class Action {}; window.top.callback(new Action)'>")
doc.write("<body onload='window.top.callback({})'>")
doc.close()
function callback(obj) {
console.log(isPlainObject(obj))
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment