Detecting and interreacting with OnUnload Event

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ellnew
Posts: 15
Joined: 16 Apr 2019, 01:59

Detecting and interreacting with OnUnload Event

14 Jun 2021, 08:09

So just a few things to know from the top - I'm using Chrome and G33kdudes plugin to automate Chrome.

I have a window that appears on a webpage I'm trying to automate. I'm not sure if it functions as a popup, or a unload event listener. I assume it's the latter as when I attempt to navigate away from a page I get the attached prompt.

It is not always a guarantee that this event listener will popup it seems to be about 50/50, so I'm trying to find a piece of Autohotkey code that is able to detect this event listener and then press enter if the event listener pops up.

Thanks in advance.
Attachments
Unload.PNG
Unload.PNG (7.58 KiB) Viewed 328 times
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Detecting and interreacting with OnUnload Event

14 Jun 2021, 14:08

I think an event you are interested in is beforeunload. You can try to just clear it by evaluating the js code:

Code: Select all

window.onbeforeunload = function() { }
ellnew
Posts: 15
Joined: 16 Apr 2019, 01:59

Re: Detecting and interreacting with OnUnload Event

15 Jun 2021, 03:53

Hi, thanks for the reply. I'm quite new to AutoHotkey, so I'm wondering if it's possible to write the whole function out as an example. What sort of functions should be contained within the brackets to either accept or dismiss this popup?
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Detecting and interreacting with OnUnload Event

15 Jun 2021, 04:22

That is not an AHK code, but javascript. That code should be evaluated as it is via PageInst.Evaluate("window.onbeforeunload = function() { }"). The function is really blank, this is needed to clear a beforeunload event handler. There is no guarantee that this will work, it's just an attempt.
ellnew
Posts: 15
Joined: 16 Apr 2019, 01:59

Re: Detecting and interreacting with OnUnload Event

15 Jun 2021, 07:10

Hey thanks again teadrinker, I tried this method but it doesn't seem to do the trick. I still get the pop-up occasionally and I need a stable way to interact with it.

Is there a way to create a sort situational 'IF' statement that analyses as to whether a beforeunload pops up, and if it does then to send enter?
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Detecting and interreacting with OnUnload Event

15 Jun 2021, 08:47

To answer your question, I need real page to test.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Giresharu, supplementfacts and 137 guests