ParentPage
Js File:-
//Last
recieved value.
var last = 0;
//Url of iframe page
var url = "iframe
page url";
//Send message to iframe.
function toIFrame() {
//Get the iframe.
var iFrame = document.getElementById("iframepage").contentWindow;
//Send the message to iframe.
iFrame.location =
url + "?message=" + new Date().getTime();
}
//Get the message on document load.
$(document).ready(function () {
//Message.
var message;
//Get the query string value.
var qstring = location.href.split('?');
//Check whether query string exist or not.
if
(qstring.length > 1) {
//Get the message.
message =
qstring[1].split('=')[1];
//Append the message to body.
$('<div/>').html(message).appendTo('#output');
}
});
<div>
<div>
<input type="button"
value="ToIFrame"
onclick="return
toIFrame();" />
</div>
<iframe id="iframepage"
src="iframe page url "
width="400" height="300"
border="1"></iframe>
<div id="output">
</div>
</div>
IFramePage:-
//Last recieved value.
var last = 0;
//Url of parent page
var url = "parent
page url ";
//Send message to parent page.
function toParent() {
//Send message to parent.
window.parent.location = url + "?message="
+ new Date().getTime();
}
//Get the message on document load.
$(document).ready(function () {
//Message.
var message;
//Get the query string value.
var qstring = location.href.split('?');
//Check whether query string exist or not.
if (qstring.length > 1) {
//Get the message.
message = qstring[1].split('=')[1];
//Append the message to body.
$('<div/>').html(message).appendTo('#output');
}
});
<div>
<input type="button"
value="ToParent"
onclick="return
toParent();" />
</div>
<div id="output">
</div>
Let me know, if you have any feedback. Mail me for source code. Enjoy reading my articles…
sekhartechblog@gmail.com
No comments:
Post a Comment