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 Disable Js window.close and let's everthing stay OK?

Post Reply
crystalxp
Posts: 39
Joined: Tue Jul 04, 2017 8:23 am

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

Post 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 .
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

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

Post 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.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

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

Post 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.
crystalxp
Posts: 39
Joined: Tue Jul 04, 2017 8:23 am

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

Post by crystalxp »

Cool, I have tested it ,and everyone now ok as it is . Thx again for your works
Post Reply