How can I close a modal with the Esc key? I believe there has to be some JS code to solve it. I believe my question is hidden in ‘wwLib.getFrontDocument()’. Where do I have to implement the code to achieve the close function on all my pages?
1 Like
I’d say you should add the code on page load, on every page where you might have the popup.
thank’s for the quick answer! Do you can serve me also the code which return me for example “true” when the esc key is pressed so i can continue my workflow with the changed value?
A tip that might save you a lot of time,
Anything JS related, use a query “[How do I do this]” followed by “stackoverflow” in stupid simple language.
var msg = wwLib.getFrontDocument().getElementById('state-msg');
wwLib.getFrontDocument().body.addEventListener('keypress', function(e) {
if (e.key == "Escape") {
msg.textContent += 'Escape pressed:'
}
});
1 Like
@Broberto Why wwLib.getFrontDocument().body.addEventListener
rather than wwLib.getFrontDocument().addEventListener()
?