# Wie kann ich das Modal Open - Event abfangen?

**URL:** <https://forum.shopware.com/t/wie-kann-ich-das-modal-open-event-abfangen/96807>\
**Category:** Shopware 6 (German)\
**Created:** [23. Oktober 2022 um 22:25 UTC](https://forum.shopware.com/t/wie-kann-ich-das-modal-open-event-abfangen/96807 "2022-10-23T22:25:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilja](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/ilja/32/20593_2.png) [@ilja](https://forum.shopware.com/u/ilja)\
**Post date:** [23. Oktober 2022 um 22:25 UTC](https://forum.shopware.com/t/wie-kann-ich-das-modal-open-event-abfangen/96807/1 "2022-10-23T22:25:57Z")

</div>

Hi all,

ich möchte mich auf das modal open - Event subscriben, aber bekomme es leider nicht hin.  
In der Developers-Doku ist folgendes Beispiel aufgeführt, doch leider kann ich nur wenig damit anfangen.

```auto
import Plugin from 'src/plugin-system/plugin.class';

export default class EventsPlugin extends Plugin {
    init() {
        const plugin = window.PluginManager.getPluginInstanceFromElement(document.querySelector('[data-cookie-permission]'), 'CookiePermission');
        plugin.$emitter.subscribe('hideCookieBar', this.onHideCookieBar);
    }

    onHideCookieBar() {
        alert("The cookie bar has been hidden!");
    }
}

```

Ich habe folgende Plugin-Bezeichnung für das Modal ausfindig gemacht: AjaxModal (ich hoffe, es ist die richtige)

Das wäre mein Code in meinem Plugin-Init:

```auto
const plugin = window.PluginManager.getPluginInstanceFromElement(document.querySelector('.js-pseudo-modal'), 'AjaxModal');
plugin.$emitter.subscribe('onOpen', this.onModalOpen);

```

Kann mir dabei jemand helfen?

Danke vorab!  
Ilja

---

<div class="post-metadata">

**Author:** ![abdullah](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@abdullah](https://forum.shopware.com/u/abdullah)\
**Post date:** [24. Oktober 2022 um 09:21 UTC](https://forum.shopware.com/t/wie-kann-ich-das-modal-open-event-abfangen/96807/2 "2022-10-24T09:21:42Z")

</div>

hallo,

ich würde zu erst überprüfen, ob auch das richtige Plugin selektiert wird. Welche Instanz hat deine Konstante „plugin“?

Im nächsten Schritt ist zu überprüfen, ob das Event „onOpen“ auch wirklich „gepublished“ wird, oder ob eventuell nicht ein anderes Event beim Öffnen des Modals „gepublished“ wird.

vg

---

<div class="post-metadata">

**Author:** ![ilja](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/ilja/32/20593_2.png) [@ilja](https://forum.shopware.com/u/ilja)\
**Post date:** [24. Oktober 2022 um 13:32 UTC](https://forum.shopware.com/t/wie-kann-ich-das-modal-open-event-abfangen/96807/3 "2022-10-24T13:32:03Z")

</div>

Okay, ich habe es geschafft.

```auto
init() {
  const modalDataAttr = Feature.isActive('V6_5_0_0') ? 'data-bs-toggle="modal"' : 'data-toggle="modal"';
  const modalPlugin = window.PluginManager.getPluginInstanceFromElement(document.querySelector(`[${modalDataAttr}][data-url]`), 'AjaxModal');
  
  modalPlugin.$emitter.subscribe('ajaxModalOpen', this.onModalOpen.bind(this));
}

onModalOpen(event) {
 // your code here
}

```
