Jump to content
Sign in to follow this  
oMBRa

Handle close event of IE

Recommended Posts

oMBRa

is possible to handle the close event of IE as we can do with gui :GUISetOnEvent($GUI_EVENT_CLOSE, 'myfunc')

Share this post


Link to post
Share on other sites
oMBRa

is possibile to prevent it to be closed?

Share this post


Link to post
Share on other sites
DaleHohm

is possibile to prevent it to be closed?

Not from AutoIt. AutoIt handles COM event asynchronously, so you cannot Cancel them.

You can use _IEHeadInsertEventScript to inject Javascript onto the page and handle the event from there.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
oMBRa

wich is the name of the event when u click the close button?

I tried ''OnQuit'' with no results

Share this post


Link to post
Share on other sites
DaleHohm

OnQuit is an event on the internetexplorer object that is not accessible to the DOM, but you can trap the onbeforeunload event of the window object that gets fired before a Quit.

_IEHeadInsertEventScript ($oIE, "window", "onbeforeunload", "your script")

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
oMBRa

Thanks for your help Dale, but now whenever you click the close button, IE dislays an annoying message that asks you if u want exit or not... is there any event that can be handled to prevent to dislay that mesage?

Share this post


Link to post
Share on other sites
Authenticity

Try this:

#include <IE.au3>
HotKeySet('{ESC}', '_EXIT')

Dim $sKey = 'HKCU\Software\Microsoft\Internet Explorer\New Windows'

RegWrite($sKey, 'PopupMgr', 'REG_SZ', 'no')
Dim $o_IE = _IECreate('http://www.autoitscript.com/')
_IEHeadInsertEventScript($o_IE, 'window', 'onunload', 'window.open("about:blank");')

While 1
    Sleep(20)
WEnd

Func _EXIT()
    RegWrite($sKey, 'PopupMgr', 'REG_SZ', 'yes')
    Exit
EndFunc

Share this post


Link to post
Share on other sites
oMBRa

it keeps showing that message, dont know why

Share this post


Link to post
Share on other sites
DaleHohm

Thanks for your help Dale, but now whenever you click the close button, IE dislays an annoying message that asks you if u want exit or not... is there any event that can be handled to prevent to dislay that mesage?

Sorry. From MSDN:

When a string is assigned to the returnValue property of window.event, a dialog box appears that gives users the option to stay on the current page and retain the string that was assigned to it. The default statement that appears in the dialog box, "Are you sure you want to navigate away from this page? ... Press OK to continue, or Cancel to stay on the current page.", cannot be removed or altered.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.