Execute javascript on pop up windows.

427 views
Skip to first unread message

Cantalsoft France

unread,
May 12, 2015, 4:50:41 AM5/12/15
to cefs...@googlegroups.com
I'm currently using CEF 39.0.1.0 in a .net 4.0 windows application.
I implements ILifeSpanHandler interface and  had this code in OnBeforePopup method

public bool OnBeforePopup(IWebBrowser browser, string sourceUrl, string targetUrl, ref int x, ref int y, ref int width, ref int height)
{
browser.ExecuteScriptAsync("alert(document.title);");
return false; 
}

The javascript alert fire but it return the main window titile.

Can you help me ?

Alex Maitland

unread,
May 12, 2015, 5:00:49 AM5/12/15
to cefs...@googlegroups.com

Access to popups is not currently exposed in `39`. The next version (`41`) will expose much more of the underlying `CEF API` and provide that functionality.

Version `41` is a work in progress you can check it out at https://github.com/cefsharp/CefSharp/tree/cef/2272 though the `API` is yet to stabalise, so be warned.
There are still likely a few missing pieces to implement before what your attempting to do will work properly.

For reference `OnBeforePopup` is called before a popup is created, so it's too early to execute script on a popup.

Can you reference the popup in javascript? Like get a handle to it's window object and access it's elements? (Been a while since I toyed with popups in javascript, so I can't provide any specifics.).

Cantalsoft France

unread,
May 12, 2015, 5:10:57 AM5/12/15
to cefs...@googlegroups.com
What I really need is to close a pop up window after is load based on its title.
Do you think it's possible in 39 ?

Thx

Alex Maitland

unread,
May 12, 2015, 5:17:40 AM5/12/15
to cefs...@googlegroups.com
You can close the window in javascript, so it's quite likely.

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_close

Something like below might work, you'll have to investigate further.
http://stackoverflow.com/questions/3030859/detecting-the-onload-event-of-a-window-opened-with-window-open
Reply all
Reply to author
Forward
0 new messages