Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

How to supress JavaScript Confim dialog?

Post Reply
Christoph
Posts: 25
Joined: Fri Feb 23, 2018 6:31 am

How to supress JavaScript Confim dialog?

Post by Christoph »

Hello,

using CEF4Delphi (Delphi 10.2 Tokyo) as shown in the demo "JSWindowBindingSubProcess" (GlobalCEFApp.BrowserSubprocessPath := 'SubProcess.exe';) and loading a page leads us to a JavaScript Confim dialog, if we click on a button in this page where JavaScript code is executed and a new window should be opened. Then we get a JavaScript Confim dialog with the question "Is it OK to leave/reload the page?"

Is there any way to supress the JavaScript Confim dialog?

We did try OnJsDialog without success...

May it is possible to set GlobalCEFApp.JavaScriptFlags in the dpr-file? If yes, what value(s) would be the right one(s)?

Thank's in advance!
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to supress JavaScript Confim dialog?

Post by salvadordf »

Hi,

That dialog can be suppressed if you use a custom popup window like the PopupBrowser demo does.
That demo uses TChromium.CloseBrowser(True) in the destruction sequence to ignore the 'onbeforeunload' javascript event.

I've never used the javascript flags but this is what the CEF code comments say about them :

Code: Select all

  ///
  // Custom flags that will be used when initializing the V8 JavaScript engine.
  // The consequences of using custom flags may not be well tested. Also
  // configurable using the "js-flags" command-line switch.
  ///
This might be a relevant comment about those flags in the "v8-users" group :
https://groups.google.com/forum/#!topic ... LZxrhv-wks

If you want to take a look, these are the javascript flags :
https://github.com/v8/v8/blob/master/sr ... initions.h

Anyway, I would recommend to use the code in the PopupBrowser demo.
Christoph
Posts: 25
Joined: Fri Feb 23, 2018 6:31 am

Re: How to supress JavaScript Confim dialog?

Post by Christoph »

Thank you for the immediate response.

just to inform the community about the solution we did find in the meantime:

we use

procedure TBrowserView.Chromium1BeforeUnloadDialog(Sender: TObject;
const browser: ICefBrowser; const messageText: ustring; isReload: Boolean;
const callback: ICefJsDialogCallback; out Result: Boolean);
begin
inherited;
Result := True;
end;


and


procedure TBrowserView.Chromium1SetFocus(Sender: TObject;
const browser: ICefBrowser; source: TCefFocusSource; out Result: Boolean);
begin
inherited;
if source = TCefFocusSource.FOCUS_SOURCE_NAVIGATION then
Result := True;
end;
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to supress JavaScript Confim dialog?

Post by salvadordf »

I forgot about the TChromium.OnBeforeUnloadDialog event.

I'm glad you found an easier solution! :)
Post Reply