Question:
how to exchange messages between iframe and parent other than postMessage. Why not postMessage, because it is necessary to exchange not only variables, but also transfer functions without conversion to JSON, for example, there is the following,
let someConfig = {
let someData = 'someVar';
someFunction() {....}
........................
}
so that this data is transferred to the child frame, and yes the child frame is in a different domain
Answer:
but also pass functions without conversion to JSON
I think it was supposed to transfer objects with variables, functions ..
look at this
scroll down, exhale, "relax and have fun."
if I am wrong in my assumption:
however, no one forbids doing so
function conteiner() {
return new class CL {
constructor() {
this['param1'] = 'some val'
this['count'] = 4
this['show'] = function () {
for (var i = this['count']; i > 0; i--) {
console.log(i, this['param1'])
}
}
}
}
}
let str = conteiner.toString()
let doIT = `
let foo = ${str}
let cl = foo()
cl['show']()
`
//передаём строку doIT
//и исполняем
eval(doIT)
also, I recommend to look at this article from 2009 and comments to it.