How to set/change window.parent

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to set/change window.parent

Postby yanivt » Sun Dec 06, 2020 11:25 am

Hi
is there a way via cef to change Window.parent in the html.
mean:
i am using mdi application , and i have my main browser, i want to open new forms with new browser inside , and set the Window.parent to be the one that belong to my main window.
i can get the same behavior if its was iframe but i dont want to use iframe .

any idea ?
thanks
Yaniv
yanivt
Techie
 
Posts: 12
Joined: Sun Dec 06, 2020 11:10 am

Re: How to set/change window.parent

Postby magreenblatt » Sun Dec 06, 2020 12:01 pm

Window.parent cannot be set directly. You need to create the child browsers using JavaScript window.open and they need to have the same origin as the main browser.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to set/change window.parent

Postby yanivt » Sun Dec 06, 2020 2:07 pm

Thanks for the clarification.
is there a way to handle the windows open , to put my new browser in my specific Form(windows/view) ?
(its mdi application so i want to use my view)

thanks allot
Yaniv
yanivt
Techie
 
Posts: 12
Joined: Sun Dec 06, 2020 11:10 am

Re: How to set/change window.parent

Postby magreenblatt » Sun Dec 06, 2020 2:24 pm

You can set the CefWindowInfo in OnBeforePopup.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to set/change window.parent

Postby yanivt » Sun Dec 06, 2020 2:50 pm

great !
if i am working with CEFSharp is it , so i need to do it via ILifeSpanHandler ?
e.g.
chromeBrowser.LifeSpanHandler = xxxx

or other object/class

thanks
yanivt
Techie
 
Posts: 12
Joined: Sun Dec 06, 2020 11:10 am

Re: How to set/change window.parent

Postby amaitland » Sun Dec 06, 2020 5:57 pm

Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: How to set/change window.parent

Postby yanivt » Mon Dec 07, 2020 10:34 am

Thanks .

i follow the topic , and i manged to open my new window.
but its seems like i could not keep the parent document , like its not recognize in the child windows, what do i miss.
here is my code snippets
html
Code: Select all
<button onclick="window.open('main2.html');">Try new window open JS</button>


C#
Code: Select all
      public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame,
        string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture,
            IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings,
            ref bool noJavascriptAccess, out IWebBrowser newBrowser)
            {
            var xxx = (CefSharp.WinForms.ChromiumWebBrowser)chromiumWebBrowser;
            xxx.Invoke(new Action(() =>
            {
                Form3 c = new Form3(null);
                c.MdiParent = FormMain.g_singleFormMain;
                c.Show();
               
            }));
            noJavascriptAccess = true;
            newBrowser = null;
            return true;
}


thanks for any idea
btw
the major issue is to have access to parent js function
yanivt
Techie
 
Posts: 12
Joined: Sun Dec 06, 2020 11:10 am

Re: How to set/change window.parent

Postby amaitland » Mon Dec 07, 2020 2:44 pm

You are canceling the popup creation by returning true.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: How to set/change window.parent

Postby yanivt » Mon Dec 07, 2020 3:10 pm

i appreciate your assistance.

i noticed when i return false - default window is started outside my MDI app.
i want to open the new window in my mdi , i managed to do that via the code i presented above.

my JS open.window looks like this
Code: Select all
        function openChild(file,window) {
                 childWindow=open(file,window);                       
                childWindow.parent = self;
        }


on standards chrome all works well. the only thing i wanted is to have access to parent from the new window/browser , while using CEF in my MDI app.
so, when we call to openChild method , i create the new form with the target url and set in in my mdi app (OnBeforePopup) , but the parent is not set as expected.

There is more - when i ignored the OnBeforePopup (lifespanhandler) , and let the default behavior to start the pop-up, even than i could not access to the parent ,although i set it in the JS method...

best regards
yaniv
Last edited by yanivt on Mon Dec 07, 2020 3:32 pm, edited 1 time in total.
yanivt
Techie
 
Posts: 12
Joined: Sun Dec 06, 2020 11:10 am

Re: How to set/change window.parent

Postby amaitland » Mon Dec 07, 2020 3:31 pm

In viewtopic.php?f=18&t=18045#p47577 I've linked to the relevant code to host the browser as a tab, you can adapt that to host as a mdi child.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Next

Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 53 guests