How do I add an onclick event to close an open window?

I would like to add a button or link that will allow the user to close the browser window. I have had temporary success by adding javascript (onclick) to the code in the text editor but the code goes away.

Note: I am not a developer but am good at making small (obvious) modifications and copying and pasting!

Thanks for any instructions anyone might be able to provide.

These days you can only close a browser window/tab using javascript if the window/tab has been opened via javascript and it is stored in a variable.

Example:

Open your browsers developer tools.
Now click the console tab in the tools.

Now paste this:

var testing = window.open( 'https://google.com' );

It will spit out some variable stuff and a new window will open to google.com

Now in the console type testing.close(); and it will close again.

You cant just close the window tab you are in. Imagine if websites were able to do that!

Thank you!

So I would need to use javascript to open the new window. I don’t know how to do this in Beaver Builder.

I have a page with a summary of some content and a button that says “Learn more” that opens a new window for the full content. It sounds like I need to use javascript to open that new window (and close it) …

I know in BB in the Advanced tab of the text editor there is a place to put javascript, but I don’t know how to attach that behavior to the button itself. Any guidance (bearing in mind I’m not a developer) would be much appreciated!