Skip to content

Instantly share code, notes, and snippets.

@timdorr
Created Nov 8, 2017
Embed
What would you like to do?
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