Search code examples
jquerynoty

how to close jquery noty confirm message when pressing enter key


i have a jquery noty implementation in my project. Using this I display a modal message in my page. The modal message is closing while I press the OK button of the message. Now I need to close the message upon enter key press. How I can perform this. Please help

    <script type="text/javascript">
        function generatemodal(type, layout, textcontent) {
            var n = noty({
                text: textcontent,
                type: type,
                modal: true,
                layout: layout,
                theme: 'defaultTheme',
                buttons: [
                    {
                        addClass: 'btn btn-primary', text: 'Ok', onClick: function ($noty) {
                            $noty.close();

                        }
                    }
                ]
            });
            console.log('html: ' + n.options.id);
        }

        function generatemodalcall(mess) {

            generatemodal('warning', 'center', mess);

        }


</script>


Solution

  • Maybe this?

    $(document).keypress(function(e) {
        if(e.which == 13) {
            $.noty.closeAll();
        }
    });