Label

  • ActionScript 2
  • AD Player 2
  • Algorithm 2
  • AS3 16
  • Audio 1
  • Audio Description Player 1
  • Bitmap 1
  • BitmapData 1
  • Browser 1
  • C# Experience 4
  • Chart 1
  • Flash 10
  • Game 1
  • Geometry 1
  • JavaScript 2
  • Mathematics 6
  • Music Online 1
  • MVC 1
  • Performance 1
  • PureMVC 1
  • Slide 1
  • Talks 1
  • Tool 1
  • Tool Player 1
Toggle Side
Home   »   JavaScript   »   Pass data from popup to parent on multi browsers

Pass data from popup to parent on multi browsers

Today I’m going to support a small issue for my co-worker working with browser popup.
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

Conclusion

Working with multi-browsers is amazing for any developers I think, because we will have chance to get more differences between them, sometime we also get mad because we do not have any way to resolve a huge issues  between them, meanwhile Google also has no clearly defined problem. The version of the browsers are also thing we have to concern.

Download

Click here!

Labels: Browser ,  JavaScript   at:  2:04 AM     Email This BlogThis! Share to X Share to Facebook

0 comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments ( Atom)
© Hung Le 2007-2016. Powered by Blogger