Iframe sending variable to parent window




Hello,
 We know that using a variable value from IFRAME window to parent window is not secure . thats why javscript add postMessage function to use variable in parent window here is an example


1.  Add this script in  Parent Windows



window.addEventListener('message', receiveMessage, false);

function receiveMessage(event)
{
 document.getElementById("phone_verify").value = event.data;
}



2. Add script in Iframe Windows to post variable
           var pv = "123"
            var parent = window.parent;
            var targetOrigin = "http://localhost/website1";
            if (parent && parent.postMessage) {

                parent.postMessage(pv , targetOrigin);

            }


3.  Using this we can also
"SecurityError: Permission denied to access property “tinymce” on cross-origin objectolve this issue " .  error in consol


Thank you 

No comments:

Post a Comment

Pages