Page 1 of 1

How To Disable Js window.close and let's everthing stay OK?

Posted: Mon Mar 25, 2019 4:58 am
by crystalxp
Hello,Thanks for your great job, I have a problem in disable Js window.close
Some web page will use javascript "window.close" to close web window,but it's bad for me ,becacuse whole application will terminated after that,
so i use onClose event and give a Result:=True Value to prevent this operation.
but after this ,the TChromium's FClosing will changed to true,this cause the OnJsDialog and ShowDevTools function runs in wrong judgement....now time, I Used the class helper to intrude this value.... or maybe OnClose event should Sending the FClosing Value to inner to change it's value...

My question is "How to prevent Js window.close() operation and let's TChromium's statues goes ok"?

Waiting for your suggestion...thank you .

Re: How To Disable Js window.close and let's everthing stay OK?

Posted: Mon Mar 25, 2019 11:53 am
by salvadordf
Setting TChromium.Options.JavascriptCloseWindows to STATE_DISABLED before the TChromium.CreateBrowser call should stop JavaScript code from closing windows that were not created by JavaScript but I've seen some contradictory information about this setting and I don't have much time to test it.

I'll modify the TChromium.OnClose event the next time there's a new version of the CEF binaries. It will replace the "Result" parameter for other parameter that allows to cancel, close or delay the closing sequence.

If you need to access a protected field or change the way some protected procedure works you can always create a custom class that inherits from TChromium and you will be able to override almost everything. I rarely use private fields in CEF4Delphi and many procedures and functions are virtual to allow full access to inherited classes. If I forgot to declare a procedure as virtual and you need to override it, just tell me and I'll make it virtual.

There is no need to create class helpers.

Re: How To Disable Js window.close and let's everthing stay OK?

Posted: Thu Mar 28, 2019 10:44 am
by salvadordf
Please, download CEF4Delphi again from GitHub :
https://github.com/salvadordf/CEF4Delphi

Modify the TChromium.OnClose event in your app and set the new aAction parameter to cbaCancel to stop closing the browser.

Re: How To Disable Js window.close and let's everthing stay OK?

Posted: Thu Mar 28, 2019 5:00 pm
by crystalxp
Cool, I have tested it ,and everyone now ok as it is . Thx again for your works