How to pass data from popup to parent window on IE or Chrome or others for example?
What is similar of some browsers supporting? Let me show you somethings that I have summarized:
Browser | Method should be used | Return by |
---|---|---|
IE 6, 7, 8,9,Edge | window.showModalDialog | window.returnValue |
Chrome, Opera, Firefox, Safari | window.open | window.opener.passDataToParent |
Example how to get a message from popup
I create 2 pages parent.html and popup.html, on the parent page I will have a method use to open the popup page.On parent.html
<script language="javascript">
function passDataToParent(txt) {
//data will be received from popup page
}
function callOpenPopup() {
// popup page will be opened at here!
}
</script>
On popup.html
<script language="javascript">
function callPassData() {
var d = "data for passing";
// pass data to parent at here
}
</script>
<input value="call popup" type="button" onclick=" callPassData() " />
And with
IE 6,7,8,9 and Edge we should use with this method
//Parent.html uses to open popup window.showModalDialog(); //Data passes from popup.html to parent.html var value = new Object(); value.data = d; window.returnValue = value;
Chrome, Opera, Firefox, Safari we should use with this method
//Parent.html uses to open popup window.open(); //Data passes from popup.html to parent.html window.opener.passDataToParent(d);
Cross domain should pay attention
We could not to be able to pass data from another popup domain to another parent domain.For example:
http://domain.a.com/parent.html
http://domain.b.com/popup.html
0 comments:
Post a Comment