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.

Re: How to set/change window.parent

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

Great sample !!
btw :

when i ignored the OnBeforePopup (lifespanhandler) and decided to goto default behavior to start the pop-up,
even than i could not access to the parent ,although i set it in the JS method...
Code: Select all
     function openChild(file,window) {
                 childWindow=open(file,window);                       
                childWindow.parent = self;
        }


could it be a bug ?
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 4:11 pm

Does it work in Chrome?
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 » Tue Dec 08, 2020 2:43 am

yes its working from chrome - i checked that.
e.g.
main1.html
Code: Select all
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>

    <script type="text/javascript">
        function aaa(obj1){
            obj1.textContent = "hello from main1";
        }
        function openChild(file,window) {
                 childWindow=open(file,window);
                if (childWindow.opener == null)
                    childWindow.opener = self;

                childWindow.parent = self;
        }
    </script>
</head>
<body>
    <h1 id="heading">Hello test1</h1>
    <p>
        <button onclick="openChild('main2.html','main2');">Try new window open JS</button>
    </p>
    <h2>parent header</h2>

    <p id="para">

    </p>

    <script>
       aaa(document.getElementById('para'));
    </script>
</body>
</html>


main2.html
Code: Select all
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <h1 id="heading">Hello test2 -  without BindObjectAsync</h1>
    <br />
 
    <h2>parent header</h2>
    <p id="para">

    </p>
    <script>
       window.parent.aaa(document.getElementById('para'));
    </script>
</body>
</html>

the call to window.parent.aaa works fine when we used chrom to open main2 from main1
that what i would like to achieved.

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

Re: How to set/change window.parent

Postby magreenblatt » Tue Dec 08, 2020 9:55 am

What OS and CEF version are you using? Where are your test files hosted? How does it behave in the cefclient sample application at the same version?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to set/change window.parent

Postby yanivt » Tue Dec 08, 2020 1:41 pm

i try it on winodws 10 64bit.
i try it with CEFSharp version cef.redist.x64.86.0.24
i also try it with the cefclient.exe app version : cef_binary_85.2.11_windows32
i expect to have access to the windows.parent , but failed.

when i test the htmls sample i used a simple host server, i used live server extension from Visualstudio code.
this time its works.

the main idea is to set the window.parent of any html from outside (the opener) as you see i did after i used winodw.open js method ....
could you think on other way i can achieve that ? even programmatically ?

Thanks allot
yaniv
yanivt
Techie
 
Posts: 12
Joined: Sun Dec 06, 2020 11:10 am

Re: How to set/change window.parent

Postby magreenblatt » Tue Dec 08, 2020 1:44 pm

Please try uploading the files to a real server, and then compare the behavior in Google Chrome and cefclient at the same Chromium version.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to set/change window.parent

Postby yanivt » Tue Dec 08, 2020 1:57 pm

woooow

i test it via cefclient.exe , this time i hosted the files on server (access them via http , and not via file on disk) , and its worked.

but what its mean ? if I want to set window.parent , do i need to consume my html from real server ?? can i set it via code ? (e.g v8context global or something like that ) ?
is there any way to bypass this ? my app consume the html from local disk.
i am dealing with porting an old application to use CEF.


Thanks for your your help
Yaniv
yanivt
Techie
 
Posts: 12
Joined: Sun Dec 06, 2020 11:10 am

Re: How to set/change window.parent

Postby magreenblatt » Tue Dec 08, 2020 2:16 pm

file:// URLs are all treated as unique origins so your JS does not work. You can host the files internally using HTTP as described at https://bitbucket.org/chromiumembedded/ ... t-handling
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to set/change window.parent

Postby amaitland » Tue Dec 08, 2020 2:25 pm

The CefSharp specific version is at https://github.com/cefsharp/CefSharp/wi ... t-handling
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 » Wed Dec 09, 2020 9:19 am

thanks for the input , its much clear now - how to handle with files.

i also try to "pass" my parent via OnContextCreated with CefV8Context

e.g
Code: Select all

CefRefPtr<CefV8Value> pV8 = context->GetGlobal();
CefRefPtr<CefV8Value> my_kooko;
my_kooko =     pV8->GetValue("self");


this line cause FATAL
FATAL:v8_impl.cc(2019)] Check failed: false. invalid input parameter
Code: Select all
pV8->SetValue("kooko", my_kooko, V8_PROPERTY_ATTRIBUTE_NONE);   


is there any problem to put such object on the global context ?? i tought i could use it as window object like in js.

btw :
Is there access to CefV8Context-global in CEFSharp ?

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

Previous

Return to Support Forum

Who is online

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