-1

I am trying to open child window like this

{
  var popWindow = window.open(postUrl, "popupWindow", settings);
}

Now I want to access some parent script functions.If I directly invoke will get undefined function exception like this

(Uncaught ReferenceError: getAllFilter is not defined)

How to solve this issue.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
mak k
  • 11
  • 2
  • 7

2 Answers2

1

window.parent holds a reference to the parent of the current window or subframe.

window.parent.CallParentFuntion();

Read More on MDN

Mayank Pathak
  • 3,621
  • 5
  • 39
  • 67
0

To access the functions you can include the js-file(s) in the page of the child window. If you use inline-scripts you have to move them to js-files for this. If you only want the functions to affect the page in the child window then that will be it. If you want that the two windows influence each others state you will have to continue reading.

If the page in the window belongs to your site you can try the following code which comes from an existing answer:

var win = window.open("/path_to_page");
win.onload = function(){ alert(win.document.title); };

If you access a foreign site in the window you can use window.postMessage().

Community
  • 1
  • 1
mm759
  • 1,404
  • 1
  • 9
  • 7