26
Views
4
Comments
Solved
How to execute an action after pressing "Esc" key when hiding a sidebar?
Question

I'm developing a traditional web application using service studio 11.8.7.

Is there any way to execute a screen action when the "Esc" key is pressed to close the Sidebar Modal?

Because the "Esc" hides the modal but without executing the same screen action that the "X" icon does.

I need a way to make the "Esc" button acts same as when a user closes the modal by clicking the "X" icon.

Rank: #630
Solution

Hi Hasan,


I think you can achieve this by using JavaScript, add a listener and when the Esc key is pressed you trigger the click of your X button/link.

"document.onkeydown = function(evt) {
    evt = evt || window.event;
    if (evt.keyCode == 27) {
        document.getElementById('"+x.Id+"').click();
    }
};"

I based myself on this code: https://jsfiddle.net/m9w8m/ 


Hope it helps!


Regards,

Miguel Chaparra

Rank: #18794

Another note, I noticed that the id of the link is changeable. So I recommend to add an extended attribute (Name) and do 

document.getElementsByName('"+x.Id+"')[0].click();

instead of the Id, because it's not fixed all time.

Rank: #630

Thank you Hasan for your extra notes. It surely will help others :)


Regards,

Miguel Chaparra