# Trigger javascript alert popup message from python?

**URL:** <https://discourse.jupyter.org/t/trigger-javascript-alert-popup-message-from-python/8545>\
**Category:** Notebook\
**Tags:** how-to, help-wanted, notebook\
**Created:** [March 29, 2021, 7:34pm UTC](https://discourse.jupyter.org/t/trigger-javascript-alert-popup-message-from-python/8545 "2021-03-29T19:34:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivianoblivion](https://avatars.discourse-cdn.com/v4/letter/v/51bf81/32.png) [@vivianoblivion](https://discourse.jupyter.org/u/vivianoblivion)\
**Post date:** [March 29, 2021, 7:34pm UTC](https://discourse.jupyter.org/t/trigger-javascript-alert-popup-message-from-python/8545/1 "2021-03-29T19:34:35Z")

</div>

Hi all,  
I’m looking for a way to send a popup message from a pre- or post-save hook (python) back to the UI.

I’ve seen a few third-party ‘messagebox’ solutions but wanted to do things "the right way"™ using custom.js, but the examples I’ve seen are all bound to a toolbar widget or something in the UI – is it possible to call a “dialog.modal” javascript from python code? Any tips, examples, links, etc. appreciated.

TIA,  
John

---

<div class="post-metadata">

**Author:** ![vivianoblivion](https://avatars.discourse-cdn.com/v4/letter/v/51bf81/32.png) [@vivianoblivion](https://discourse.jupyter.org/u/vivianoblivion)\
**Post date:** [May 4, 2021, 8:04pm UTC](https://discourse.jupyter.org/t/trigger-javascript-alert-popup-message-from-python/8545/2 "2021-05-04T20:04:59Z")

</div>

I’m not sure if it’s the right or best way, but for anyone else with this issue I’ve found that you can raise HTTPError messages from python; 100s don’t display; 200s result in a messagebox, 300-500s result in a message to the toolbar area.

I then trap the error text in \notebook\static\notebook\js\notebook.js:

```
    if (data.message) {
        // JD: add custom handling for autosave storage space checking (note: 'data' does not pass the HTTP code, just the message text)
        if(data.message.startsWith("Warning: you are running low on storage space;")){
            var title = i18n.msg._("Storage Capacity Warning");
            body.append($("<p>").text(data.message));
                dialog.modal({
                    notebook: this,
                    keyboard_manager: this.keyboard_manager,
                    title: title,
                    body: body,
                    buttons : {
                        OK : {
                            "class" : "btn-primary"
                        }
                    }
                });
            this.events.trigger('notebook_saved.Notebook');
            this._update_autosave_interval(start);
            if (this._checkpoint_after_save) {
                this.create_checkpoint();
                this._checkpoint_after_save = false;
            }
        }
```
