Exit Posted May 2, 2019 Share Posted May 2, 2019 Sometimes I close the Chrome browser with the X in the upper-right corner of the window, without realizing that I have other tabs open. Is there a way to prevent the closing process or at least advance a warning? Maybe through a small GUI that is placed over the X and follows the X when it changes position? I would be grateful for relevant ideas. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
alienclone Posted May 2, 2019 Share Posted May 2, 2019 if you accidentally close multiple tabs, just re-open chrome and press ctrl+shift+t to load all tabs that were closed. Exit 1 If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
junkew Posted May 2, 2019 Share Posted May 2, 2019 Maybe if you add some javascript thry your addressbar or as a bookmarklet javascript:window.onbeforeunload = confirmExit;function confirmExit() {return "You attempt to leave this page. Are you sure?";} Not fully tested but seems to work. Maybe other events are better for above trick. Exit 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
alienclone Posted May 3, 2019 Share Posted May 3, 2019 1 hour ago, junkew said: Maybe if you add some javascript thry your addressbar or as a bookmarklet javascript:window.onbeforeunload = confirmExit;function confirmExit() {return "You attempt to leave this page. Are you sure?";} Not fully tested but seems to work. Maybe other events are better for above trick. that should work if you put the code into a page saved in your pc, then have chrome load that page every time it opens, Exit 1 If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
Exit Posted May 3, 2019 Author Share Posted May 3, 2019 @junkew and @alienclone Thank you for these suggestions. Unfortunately, I lack the knowledge to implement this. Would it perhaps be possible to provide a more detailed instruction? App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
alienclone Posted May 3, 2019 Share Posted May 3, 2019 just save the attached html document in your pc somewhere then go into Chrome settings and set it to open specific page on load and put the directory location to your file. tab close confirm.html If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 3, 2019 Moderators Share Posted May 3, 2019 Last I knew there were several Chrome extensions that do just this task, warn before closing all tabs. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
junkew Posted May 3, 2019 Share Posted May 3, 2019 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPISysWin.au3> #include <ColorConstants.au3> #include <WinAPISys.au3> Local $ySize=_WinAPI_GetSystemMetrics ( 31 ) + 8 ;~ SM_CYSIZE Local $xSize=_WinAPI_GetSystemMetrics ( 30 ) + 10 ;~ SM_CXSIZE Local $sizeBlock=40 Local $adjustment=$sizeBlock+ 8 + 6 ;~ Local $hGui=GUICreate("Test", $sizeBlock, $sizeBlock, 100, 100, $WS_POPUPWINDOW, BitOr ($WS_EX_TOOLWINDOW , $WS_EX_TRANSPARENT)) ;~ Local $hGui=GUICreate("Test", $sizeBlock, $sizeBlock, 100, 100, $WS_POPUPWINDOW) Local $hGui=GUICreate("Welcome", $xSize, $ySize, 100, 100, BitOR($WS_SYSMENU,$WS_POPUP), 0) GUISetBkColor($COLOR_WHITE,$hGui) ; Display the GUI. $hwndActive=wingethandle("[ACTIVE]", "") GUISetState(@SW_SHOW, $hGUI) WinActivate($hwndActive) ; Loop until the user exits. While 1 $hwndActive=wingethandle("[ACTIVE]", "") if ($hWndActive <> $hGui) Then $hwndPrevious=$hwndActive $aPos = WinGetPos("[ACTIVE]") $newColor=pixelgetcolor($apos[0] + $aPos[2] - 16, $aPos[1] + 4) GUISetBkColor($newColor,$hGui) EndIf ;~ WinMove($hGui,"",$apos[0], $aPos[1]) ; Apply the style _WinAPI_SetWindowPos($hGui, $HWND_TOPMOST, $apos[0] + $aPos[2] - $adjustment, $apos[1]+1, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOSIZE)) Switch GUIGetMsg() Case $GUI_EVENT_PRIMARYDOWN tooltip("You shouldnt do that, I will stop now preventing you to click on top right") ; Set the background color local $i for $i=1 to 5 GUISetBkColor($COLOR_RED,$hGui) sleep(250) GUISetBkColor($COLOR_GREEN,$hGui) sleep(250) Next ToolTip("") winactivate($hwndPrevious) exit Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Edited May 3, 2019 by junkew improved code a little with colors Exit 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Exit Posted May 3, 2019 Author Share Posted May 3, 2019 2 hours ago, alienclone said: just save the attached html document in your pc somewhere then go into Chrome settings and set it to open specific page on load and put the directory location to your file. tab close confirm.html 241 B · 1 download ☹️ Unfortunately it does not work. Although the page appears after browser start, but there is no message when I press the "close" button. All tabs have been closed. 1 hour ago, JLogan3o13 said: Last I knew there were several Chrome extensions that do just this task, warn before closing all tabs. Specific information would be helpful 14 minutes ago, junkew said: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPISysWin.au3> #include <ColorConstants.au3> Local $sizeBlock=40 Local $adjustment=$sizeBlock+8 Local $hGui=GUICreate("Test", $sizeBlock, $sizeBlock, 100, 100, $WS_POPUPWINDOW, BitOr ($WS_EX_TOOLWINDOW , $WS_EX_TRANSPARENT)) ; Display the GUI. $hwndActive=wingethandle("[ACTIVE]", "") GUISetState(@SW_SHOW, $hGUI) WinActivate($hwndActive) ; Loop until the user exits. While 1 $hwndActive=wingethandle("[ACTIVE]", "") if ($hWndActive <> $hGui) Then $hwndPrevious=$hwndActive EndIf Local $aPos = WinGetPos("[ACTIVE]") ;~ WinMove($hGui,"",$apos[0], $aPos[1]) ; Apply the style _WinAPI_SetWindowPos($hGui, $HWND_TOPMOST, $apos[0] + $aPos[2] - $adjustment, $apos[1], 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOSIZE)) Switch GUIGetMsg() Case $GUI_EVENT_PRIMARYDOWN tooltip("You shouldnt do that, I will stop now preventing you to click on top right") ; Set the background color local $i for $i=1 to 5 GUISetBkColor($COLOR_RED,$hGui) sleep(250) GUISetBkColor($COLOR_GREEN,$hGui) sleep(250) Next ToolTip("") winactivate($hwndPrevious) exit Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd This script is a good start for a solution. 🙂 I will use it. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
junkew Posted May 3, 2019 Share Posted May 3, 2019 Changed script in previous post of me a little sizing of the overlay window a little better added a pixelgetcolor to have same background as titlebar (unsure if there is a function to get actual color) Exit 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Exit Posted May 3, 2019 Author Share Posted May 3, 2019 Now I have found a way to avoid new tabs. The following registry change always opens a new window when clicking on a link. This solves my real problem. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command] ; old entry ;@="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" -- \"%1\"" ; new entry @="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --new-window \"%1\"" App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now