Friday, 3 February 2012

Crossdomain Calls Using Window Name

ParentPage Js File:-

         //Last recieved value.
         var last = 0;

        //Send message to iframe.
        function toIFrame() {

            //Get the iframe.
            var iFrame = document.getElementById("iframepage").contentWindow;

            //Send the message to iframe.
   = "message=" + new Date().getTime();

            <input type="button" value="ToIFrame" onclick="return toIFrame();" />
        <iframe id="iframepage" src=" iframe page url "
            width="400" height="300" border="1"></iframe>

        //Last recieved value.
        var last = 0;

        //Get the message on time interval.
        function getMessage() {

            //Get the window name.
            var wName =;

            //Check the window name value.
            if (wName) {

                var message;

                //Get the messgage.
                message = wName.split('=')[1];

                //Check the last value with current value.
                if (last != message) {

                    //Assign last value.
                    last = message;

                    //Append the message to body.

        //Timer for getting messages.
        setInterval(getMessage, 200);

    <div id="output">

Let me know, if you have any feedback. Mail me for source code. Enjoy reading my articles…

No comments:

Post a Comment