# I want stop the sounds from playing when the webpage is hidden

**URL:** https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340
**Category:** Libraries
**Created:** [April 13, 2021, 3:54pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340 "2021-04-13T15:54:00Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![LaserDenis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laserdenis/32/12685_2.png) [@LaserDenis](https://discourse.processing.org/u/LaserDenis)
#### Post date: [April 13, 2021, 3:54pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/1 "2021-04-13T15:54:00Z")

</div>

I tried to use document.hidden but I doesn’t seem to work .

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [April 13, 2021, 6:27pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/2 "2021-04-13T18:27:24Z")

</div>

Hi,

It works just fine in the [p5 web editor](https://editor.p5js.org/) :

```auto
function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  
  if (document.hidden) console.log("hidden");
}

```

It’s printing `hidden` when I switch tab or if I hide the window (I am on Firefox 😋 ).

---

<div class="post-metadata">

### Author: ![LaserDenis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laserdenis/32/12685_2.png) [@LaserDenis](https://discourse.processing.org/u/LaserDenis)
#### Post date: [April 13, 2021, 8:04pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/3 "2021-04-13T20:04:33Z")

</div>

I doesn’t seem to work on chrome.

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [April 13, 2021, 8:13pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/4 "2021-04-13T20:13:45Z")

</div>

Are you sure the window is not visible? Can you try to open a new tab and switch to it?

Also on which operating system are you running on?

---

<div class="post-metadata">

### Author: ![LaserDenis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laserdenis/32/12685_2.png) [@LaserDenis](https://discourse.processing.org/u/LaserDenis)
#### Post date: [April 13, 2021, 8:27pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/5 "2021-04-13T20:27:58Z")

</div>

Yea I tried printing in console to see if it was visible at one point but doesn’t seem to work. I’m using windows

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [April 13, 2021, 8:39pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/6 "2021-04-13T20:39:02Z")

</div>

Ok weird 😉

To test it :

- Close your browser and all the tabs

- Open it

- Go to the [p5 web editor](https://editor.p5js.org/) and copy paste the code above

- Press the run button (Ctrl+Enter)

- Minimize your window or open a new tab, make sure the window is hidden

- Inspect the console and also press F12 to see the inspector → does it show “hidden”?

From the [browser compatibility](https://developer.mozilla.org/fr/docs/Web/API/Document/hidden#browser_compatibility) section, it says that it’s supported by Chrome released in 2014…

---

<div class="post-metadata">

### Author: ![LaserDenis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laserdenis/32/12685_2.png) [@LaserDenis](https://discourse.processing.org/u/LaserDenis)
#### Post date: [April 13, 2021, 8:47pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/7 "2021-04-13T20:47:31Z")

</div>

```auto
function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  if (document.hidden) console.log("hidden");
  else
    print('visible');
}

```

but just prints visible  
I’m using the newestversion of chrome

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [April 13, 2021, 8:56pm UTC](https://discourse.processing.org/t/i-want-stop-the-sounds-from-playing-when-the-webpage-is-hidden/29340/8 "2021-04-13T20:56:34Z")

</div>

Hum, the code is not correct 😀

Also not that you can format your code by using the `</>` button when editing a message or use backticks around your code : ``` code ``` → `code`
