Quit/Close Browser Windows Button

Working on a project and it is a basic welcome/goodbye site for employees at our Agency (HR spearheaded). So I have most done already interns of the content and animations.

Of course they want me to add a close window button versus staff just clicking the X, or just typing a new web address as they can use the browser window to do what they want anyway.

Not very familiar with coding (javaScript) but went online and found these examples and have tried adding a button on my layout with different ways to add these different snippets with OnClick option but can't get it to work. Any suggestions advice?

The first method created a button that, when clicked, prompts the user "Do you want to close this window?" If the user clicked OK, the window would close.

<input type="button" value="Close this window" onclick="self.close()">

The second method required a bit more work, but avoided the "prompting issue". The following lines of code were to be inserted into the head of an HTML document:

_<script language="javascript" type="text/javascript"> function windowClose() { window.open('','parent',''); window.close(); } </script>

Then, the following line of code was to be inserted into the body of the HTML document:

<input type="button" value="Close this window" onclick="windowClose();">

  1. Select an Element
  2. In the Actions Inspector add an action for On Mouse Click
  3. Set it to Run JavaScript…
  4. Create New Function and paste this code:
	window.open('','_parent','');
	window.close();

Seems to work on me for Safari. This does look like a hack though - browsers typically have some security provisions that may prevent this from working in the future.

Thanks for the reply, will try it out just so I get comfortable with the steps. I get angry sometimes when they ask for options that really do not make sense to me that I don’t think the problem through. In the end came up with a better solution.

I have a GPO load their default browser to the project I am working on. Now I changed the close window concept to butte that goes to another URL instead, our Agency Resource Links page. Since I have the system opening a browser at login anyway instead of closing it why not give them quick option to go to a page they can use ;D

Of course, one day I will have to come up with using scripts and more advanced options so I should delve into it, but now I can o it on my own pace.

Sweet, and at my own pace works much faster when people like yo help out, thanks. Just tested and it works with Safari and Chrome. Will keep that to myself :smiley: for now and use in the future if needed, keeping in mind browser updates and such.

1 Like

Glad you got it!