jquery - Javascript changes variable when changing iFrame height -
i build script changed iframe height when child loaded in iframe. when console.log value, returns integer. when change iframe height value child send, variable changed value last time when function worked. spend 1 day find out bug.
the code in child:
(function() { // page initialization code here // dom available here window.parent.postmessage( // height of content document.body.scrollheight // set target domain ,"*" ) })(); };
the code in parent gave wright height:
function listenmessage(msg) { var before = msg.data; if(before % 1 === 0) { console.log(before); } } if (window.addeventlistener) { window.addeventlistener("message", listenmessage, false); } else { window.attachevent("onmessage", listenmessage); }
the code in parent gave wrong height:
function listenmessage(msg) { var before = msg.data; if(before % 1 === 0) { document.getelementbyid('receiver').height = before; } } if (window.addeventlistener) { window.addeventlistener("message", listenmessage, false); } else { window.attachevent("onmessage", listenmessage); }
i hope can tell me difference between 2 parent codes.
Comments
Post a Comment