Need help with handling popups

Having problems with building or using the JCEF Java binding? Ask your questions here.

Need help with handling popups

Postby JohnnyTheHun » Sun Feb 17, 2019 4:45 am

Hello,

Our webpage sometimes sends a file to download via the javascript window.open(...), e.g.:
window.open('https://oursite.com/Downloads/something.xls');

I have a downloadhandler added to the cefclient and if I use the php command header("Location: 'https://oursite.com/Downloads/something.xls'''); instead of a javascript window.open(...) the download works perfectly.

The window.open method works on a desktop chrome browser. But if I use the window.open method from our integrated java-cef browser it currently only opens a blank popup window.
To check what's happening I added a LifSpanHandler:
Code: Select all
 
client_.addLifeSpanHandler(new CefLifeSpanHandlerAdapter() {
            @Override
            public boolean onBeforePopup(CefBrowser br, CefFrame cf, String url, String target_frame_name) {               
                System.out.println("On Before popup: url="+url+", target_frame_name="+target_frame_name);
                System.out.println("Client: "+br.getClient()); //this shows the same String as client_.toString();
                return false;
            }
        });

And it shows that url is https://oursite.com/Downloads/something.xls as it should be, so it is trying to open a popup for the file.

I want the download handler to work in the window.open(...) situation too, what would you recommend?

Thank you!
JohnnyTheHun
Techie
 
Posts: 19
Joined: Tue Apr 10, 2018 12:24 pm

Re: Need help with handling popups

Postby Phylanx » Mon Feb 18, 2019 2:01 am

My quick guess would be that for the new window a new CefBrowser is created.
You would have to add a DownloadHandler there too.
Phylanx
Expert
 
Posts: 116
Joined: Thu Aug 11, 2016 8:17 am

Re: Need help with handling popups

Postby JohnnyTheHun » Mon Feb 18, 2019 3:39 pm

If I understand correctly you would recommend me to handle the popup in the onBeforePopup function and return true so it doesn't get handled again?

That might work, but I still don't understand why it doesn't in its current state. You cannot set a downloadhandler for a CefBrowser, you can set it at the CefClient. But it seems the CefBrowser argument in the onBeforePopup is linked to the same CefClient (at least that is what I deducted since the origivel _client.toString() and the br.getClient().toString() returns the same value).

So since the downloadhandler is set at the CefClient and works in other circumstances why doesn't it work here? Should I really create a new CefClient and a New CefBrowser for the popup to download a file if a file has been requested via window.open(...)?

Janos
JohnnyTheHun
Techie
 
Posts: 19
Joined: Tue Apr 10, 2018 12:24 pm

Re: Need help with handling popups

Postby JohnnyTheHun » Sat Aug 10, 2019 2:22 pm

Has anybody found an optimal solution for this?
JohnnyTheHun
Techie
 
Posts: 19
Joined: Tue Apr 10, 2018 12:24 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 1 guest