# Function windowClose()

**URL:** <https://forums.realmacsoftware.com/t/function-windowclose/42270>\
**Category:** RapidWeaver Classic\
**Created:** [July 5, 2022, 3:10pm UTC](https://forums.realmacsoftware.com/t/function-windowclose/42270 "2022-07-05T15:10:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MagicNeico](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/magicneico/32/16431_2.png) [@MagicNeico](https://forums.realmacsoftware.com/u/MagicNeico)\
**Post date:** [July 5, 2022, 3:10pm UTC](https://forums.realmacsoftware.com/t/function-windowclose/42270/1 "2022-07-05T15:10:08Z")

</div>

I am trying to fire some javascript code to close the browser window when a button is clicked.  
Here’s my setup:  
Button config:  
 ![onclick](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/7/e/7e8bcccb30e4642b92581b2b8b50a72295fa510a.jpeg)

body config:  
 ![onclick body](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/5/5/55588e70dd932a8c4cd4def45a873258a44485c2.jpeg)

When the page is on the server, the window does not close. What have I not done correctly?  
Thanks.

---

<div class="post-metadata">

**Author:** ![teefers](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/teefers/32/8173_2.png) [@teefers](https://forums.realmacsoftware.com/u/teefers)\
**Post date:** [July 5, 2022, 3:51pm UTC](https://forums.realmacsoftware.com/t/function-windowclose/42270/2 "2022-07-05T15:51:29Z")

</div>

Most modern browsers prevent you from closing windows with javascript that were not opened with JavaScript `window.open("https://example.com") `.

There are some “hacks” out there that get around this restriction.

I haven’t tried this, but opening a blank url first in the same tab or window, then closing is supposed to be a good work around

```auto
window.open("", "_self");
window.close();

```

---

<div class="post-metadata">

**Author:** ![MagicNeico](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/magicneico/32/16431_2.png) [@MagicNeico](https://forums.realmacsoftware.com/u/MagicNeico)\
**Post date:** [July 5, 2022, 4:49pm UTC](https://forums.realmacsoftware.com/t/function-windowclose/42270/3 "2022-07-05T16:49:27Z")

</div>

I did not know that the browser behaves differently depending on how I access my home page. The button does not work when I access my web page through the URL that I right clicked from the index.html and copied from my server files (Copy URL).  
 ![index](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/9/d/9dff0843c887889c868c1a676b4794df7a87532c.jpeg)

However, if I access my page through a normal link, the close button works as intended. Woo hoo.

Thank you Doug. This was very helpful!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/system/32/25301_2.png) [@system](https://forums.realmacsoftware.com/u/system)\
**Post date:** [February 5, 2024, 11:35am UTC](https://forums.realmacsoftware.com/t/function-windowclose/42270/4 "2024-02-05T11:35:16Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
