Jump to content
Exit

Turn off the close button in Google Chrome

Recommended Posts

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.


UDF: _SingleScript()                                        If you like my post, just click the like button :)        here -->

Share this post


Link to post
Share on other sites

if you accidentally close multiple tabs, just re-open chrome and press ctrl+shift+t to load all tabs that were closed.


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah patience, how long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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,


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah patience, how long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites

 @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?


UDF: _SingleScript()                                        If you like my post, just click the like button :)        here -->

Share this post


Link to post
Share on other sites

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

>Exit code: 0

REAL search results

"Yeah yeah patience, how long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites
Posted (edited)
#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 by junkew
improved code a little with colors

Share this post


Link to post
Share on other sites
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:
#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.


UDF: _SingleScript()                                        If you like my post, just click the like button :)        here -->

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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\""

 


UDF: _SingleScript()                                        If you like my post, just click the like button :)        here -->

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

×
×
  • Create New...