-1

I have a modal and after pressing the password update button, the modal should close and an alert box should appear on my homepage. however, the alert box will not appear when the page is first opened. how can I do it? Do you have any examples you can share?

  • without seeing any of your code its hard. But you could use something like `document.getElementbyId('...').classList.toggle('hidden')` on your alert box when the home page has loaded – mrpbennett Feb 11 '22 at 13:28
  • Does this answer your question? [Launch Bootstrap Modal on Page Load](https://stackoverflow.com/questions/10233550/launch-bootstrap-modal-on-page-load) – Atilla Arda Açıkgöz Feb 11 '22 at 14:28

2 Answers2

2

If you are using the alerts provided by the browser, you have to add a EventListener to your button like:

yourCloseButton.addEventListener("click", () => {
  alert("The modal has been closed!");
});
Apollo79
  • 674
  • 3
  • 14
0

Complementing Apollo79's answer, you can also use an inline event listener, but this is no longer recommended. There are some specific cases for this, but if you really don't need one, use Apollo79's answer instead.

<button id="urButton" onclick="alertAndDisappear()">

or

yourCloseButton.onclick = function(){}

which is equivalent to the first one.

Again, only use these if you really need them