Close parent Window

helo.
in my application i use a window with iframe und src:url. In the source-url i show a window. how can i close the parent window if the child-window will be closed?
this.getTopParentView().hide();
does not work!
thx

Hello @ObiWanKenobi ,

I suppose that you have a similar structure in your app:

parent.html
  webix.ui({
  view: "window",
  id: "parentWindow",
  head: "Parent Window page",
  position: "center",
  close: true,
  body: {
    view: "iframe",
    id: "childFrame",
    src: child_origin + "page.html",
        }
  }).show();

  // parent
  // listen to messages from the iframe
  window.addEventListener("message", function (event) {
    const childIframeWindow = $("childFrame").getWindow();				
    if (event.source !== childIframeWindow) return;
    
    if (event.data?.action === "close-parent-window") {
      $("parentWindow").hide();
    }
  });

and

child.html
	webix.ui({
	view: "window",
	id: "child",
	head: "Web Page child",
	position: "center",
	close: true,
	body: { template: "iframe content" },
	on: {
	  onHide: function () {
		// child
		// send a message for the parent
		window.parent.postMessage(
		{ action: "close-parent-window" },
		parent_origin
		);
							
		// in case of the same origin 
		// window.parent.webix.$("parentWindow").hide();
		}
	}
  }).show();

As you see, you could organize cross-document messaging between the iframe and the main document using a window.postMessage().
$$(“childFrame”).getWindow() is used here to access the iframe window object.

this.getTopParentView(), if you call it inside your child iframe, e.g. in the onHide() method, returns the child window view in such a structure and you need other means to get views outside your iframe. The best method would be to use messages for views comminication as in the code snippets above, however, if you sure that you have the same origin (protocol, domain, and port) for both your pages and they both load Webix, window.parent.webix also could help to access the parent window.

Hello,

Thank you for you advice, I will try that solution (both solutions) next week und give you a feedback.