Tuesday 3 October 2017

How to close modal popup clicking outside magento2 ?

Hi in magento2 by default modal popup is not closing clicking outside the popup which is not user friendly.

So to achieve this just place the below code in the footer file or any file which is common on all pages and it will do your job. I was also going to the same issue and came out with this and it works perfect.

       
<script type="text/javascript">
    require(['jquery'],
    function($) {
  $(document).ready(function(){
  $("body").click
  (
    function(e)
    {
     var checkclass = e.target.className ;  
    if (checkclass.indexOf("_show") >= 0){

    $( ".action-close" ).trigger( "click" );
    }
     //console.log(e.target.className);

    }
  );
    });
</script>

2 comments:

  1. Keep it up admin...this article is to good. Good information in this blog post...Magento

    ReplyDelete
  2. From two weeks I was searched for "How to close modal popup clicking outside magento2 ?" in Google and unable to find the answer. So, finally I got it in your post. I'm working in Magento development company and always ready to expand my skills and resolve my queries in the blogs like yours. Thanks for this post.

    ReplyDelete