0

I have a local HTML running in IE browser. When the local HTML opens a child window which loads a page on a remote HTTP server. After a few user interactions in the child window, the final remote page runs a JavaScript to close the child window and I would like to call a function in the parent window to pass back some info before closing.

I thought I would be able to simply make the following call in the child window

window.parent.CallbackFunct();

However, the call doesn't work. I did some research and some mentioned that if the parent window loads HTML through file:\ (which is my case), the child window cannot call parent window functions due to same origin policy.

JavaScript window.opener call parent function

My above link suggests to access all pages through HTTP://, but I cannot. The parent window has to access pages from the local file system.

Is there any way that I can make it work?

Community
  • 1
  • 1
seagle
  • 23
  • 4
  • 1
    `window.opener.CallbackFunct()` should do? – mariusnn Jan 08 '14 at 22:14
  • maybe try some of the suggestions at http://stackoverflow.com/q/3076414/740639 – Walter Stabosz Jan 08 '14 at 22:19
  • @meriusnn window.opener.CallbackFunct() doesn't work either. It is the same as window.parent.CallbackFunct() – seagle Jan 09 '14 at 18:27
  • @Walter thanks for the link. It is a very comprehensive article about dealing with COP. Among the options, window.postMessage looks like the most promising way and the belief is that it will work with IE10. However, it didn't work for me in IE10. I tried the following: – seagle Jan 09 '14 at 18:32
  • 1) define and add an message listener function on the parent window; 2) in the child window, I send a message to the parent window by window.parent.postMessage('msg', '*'); – seagle Jan 09 '14 at 18:44

1 Answers1

0

You may call a parent function from child window this way:

window.opener.your_function()
Hkachhia
  • 4,463
  • 6
  • 41
  • 76