Close the Ajax Modal popup on the Esc key

I showed the popup window using Ajax, and I need to close the window when the user presses the Esc key.

Is it possible? Please help me if anyone knows about this or has done this before.

thank

+3
source share
3 answers

Here is a link through which you can easily close the window with the eascape button:

http://www.codeproject.com/KB/scripting/Javascript_for_modalpopup.aspx

hope this help.

+5
source

Add a script to your page to close the modal ESC key press

   <script type="text/javascript">

    function pageLoad(sender, args){
        if(!args.get_isPartialLoad()){
            //  add our handler to the document's
            //  keydown event
            $addHandler(document, "keydown", onKeyDown);
        }
    }

    function onKeyDown(e){
        if(e && e.keyCode == Sys.UI.Key.esc){
            // if the key pressed is the escape key, dismiss the dialog
            $find('mdlPopupExtender').hide();
        }
    } 

    </script>
+3
source

, ModalPopupExtender, , BehaviorID java script, P2 P3. :

<script type="text/javascript">
    document.onkeyup =Esc;
    function Esc()
    {
    var KeyID =event.keyCode;
     if(KeyID==27)
     {
     if($find("p2"))
     {
       $find("p2").hide();
     }
     if($find("p3"))
        $find("p3").hide();
     }
    }
</script>

we use $ find (p2) to verify that a modal popup exists on the page.

+3
source

Source: https://habr.com/ru/post/1789662/


All Articles