По клику на кнопку открыть на время окно

Как мне по клику на кнопку открыть на время окно, и чтобы через какой-то промежуток времени оно само закрылось?

div {
  display: none;
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: black;
  color: white;
}
<button>Кнопка</button>
<div>Окно</div>


Ответы (2 шт):

Автор решения: Alex Sazonov

let btn = document.getElementById('btn');
let win = document.getElementById('win');

btn.addEventListener('click', () => {
  win.style.display = 'block';
  setTimeout(() => {
    win.style.display = 'none';
  }, 1000);
});
div {
  display: none;
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: black;
  color: white;
}
<button id="btn">Кнопка</button>
<div id="win">Окно</div>

→ Ссылка
Автор решения: Sevastopol'

document.querySelector('button').onclick = e => {
  var div = document.querySelector('div');
  div.style.display = 'block';
  setTimeout(() => div.style.display = 'none', 2000);
};
div {
  display: none;
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: black;
  color: white;
}
<button>Кнопка</button>
<div>Окно</div>

→ Ссылка