How to do a popup window

How to do a popup window

by Neil Strickland -
Number of replies: 2

Although I have done some substantial work with Moodle's systems for grading quizzes and questions etc, I have only just started trying to write code that actually generates any pages, so I do not really know what I am doing yet.

I would like my page to have lots of buttons, each of which would generate a popup window.  For comparison, at /moodle/user/index.php?id=nnn I see a button marked 'Enrol users', and if I click that then a window pops up.  In more detail, a div of class modal-content appears, wrapped in several other auxiliary divs.  I would like to do something like that.  I have tried to look at the code behind the 'Enrol users' button, but everything is wrapped in multiple layers of abstraction and I am having a hard time understanding it.  Also, that example seems to rely on Ajax and the Form API, which is not relevant for me, I just want the popup to display text that is known at the time when the page is generated.

Can anyone point me to documentation, examples or particular source code files that will help me understand the approved way to generate such popups?

Average of ratings: -
In reply to Neil Strickland

Re: How to do a popup window

by Thomas Stanley-Jones -
From your description, I suspect a Modal window will accomplish what you want. Look further here:
https://getbootstrap.com/docs/4.6/components/modal/
It depends on your Moodle theme, but if it's a default theme, Bootstrap is already installed in the back end. You will only need to copy and paste the HTML on that page to get a working example.
Average of ratings: Useful (1)