<header>
  <h2 class="title">Event -> isTrusted</h2>
  <p class="description">Визначає, чи подія була ініційована користувачем.</p>
</header>
<main>
  <div class="result">
    <button id="trustedButton">Натисніть мене</button>
    <p id="message"></p>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

header h2.title {
  padding-bottom: 15px;
  border-bottom: 1px solid #999;
}

header p.description {
  font-style: italic;
  color: #222;
}

.result {
  background-color: #f8f8f8;
  padding: 15px;
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

button {
  padding: 10px 20px;
  font-size: 16px;
  margin-bottom: 15px;
}

#message {
  color: #444;
  font-weight: bold;
}
const button = document.getElementById('trustedButton');
const message = document.getElementById('message');

button.addEventListener('click', (event) => {
  if (event.isTrusted) {
    message.textContent = 'Кнопка натиснута справжнім користувачем!';
  } else {
    message.textContent = 'Цю подію було створено програмно!';
  }
});

// Виклик події програмно для демонстрації
setTimeout(() => {
  button.click(); // Викликає "programmatic" click
}, 2000);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.