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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -