Tuesday 30 September 2014

How to close the popup window by pressing escape key button or clicking outside of the popup window with jQuery.

For closing the open popup window on the click of escape key or clciking outside the popup window, We need to create one jQuery method in every modal panel .xhtml file or any other .xhtml file which is used to show the popup window as:

<script type="text/javascript">
    jQuery(document).keyup(function (e){
            var clickedID = e.target.id;
            var unicode=e.keyCode? e.keyCode : e.charCode /*This will capture the key pressed event*/
                 if(unicode==27){//Key code for escape key is 27
                 Richfaces.hideModalPanel(#{modalPanelId});
                /*var win = window.open("","_self"); r
                 win.close();*/
                }
</script>


The above method will automatically be called whenever we press any key and if pressed key is escape key then it would close the opened popup window so it will work when we press theescape key.

To close popup window when we click on the outside of the popup window, we have to call “Richfaces. hideModalPanel(‘modelPanel Id’)” on “onmaskclick”  event of rich:modalPanel as:

onmaskclick="Richfaces.hideModalPanel('#{modalPanelId}')"

No comments:

Post a Comment