Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8652235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:15:43+00:00 2026-06-12T14:15:43+00:00

I have a modal window script that we are trying to bring up to

  • 0

I have a modal window script that we are trying to bring up to speed for accessibility requirements. The requirement says that when you tab away from the window, it should close. It also says that upon dismissing the window, the original triggering element must get focus back.

After doing some digging I found this: jQuery figuring out if parent has lost 'focus'. It seemed that the easiest way to tell when you’ve tabbed away from the window is to track the focusin event, and when focus fires on an element that is not a child of the open modal, dismiss the window. This method however, is problematic as you’ll see (not to mention a little too heavy for my liking). Here is the code that handles this:

$('body').focusin(function(e) {
        if (!$(e.target).parent().is('.current-window')) {
            closeModal();
        }
    });

and the function that closes the window:

function closeModal() {
        $('.modal-mask, .current-window').fadeOut('fast', function(){
            $(this).removeClass('current-window');
            $('.modal-mask').removeAttr('style');
            $('.modal-trigger').focus();
        });
    }

Now obviously, when I run this code, closeModal() fires back and forth between the focusin event up to the maximum call stack and therefore throws the “maximum call stack exceeded” error message before giving focus to the triggering element.

Refer to this fiddle for full code: http://jsfiddle.net/pbredenberg/wxX4T/

I’m trying to think of a better way to handle this requirement, or at the very least avoid the infinite loop. Can anyone point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:15:44+00:00Added an answer on June 12, 2026 at 2:15 pm

    I am still not able to just comment, so I have to submit this as an answer:
    Why dont you track if you are actually closing the window with a bool var like window.closing?
    I updated the example: http://jsfiddle.net/kevkong/wxX4T/8/
    Is this, what you intended to do?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent page that calls an iframe modal window as follows: <script
I make some script, that have modal window on fancybox and on load it's
I have a modal window that uploads files to server. Works great. Upon completion
I have a JInternalFrame window that needs to popup a modal dialog box when
I have a modal window using jqmodal. I need a button within that modal
I am trying to showing one image in bootstrap modal, also that pop-up window
I have an asp.net app that launches a modal window upon button_click event. That
I have a fancybox modal window that loads a page of content (a form).
I am trying to rename a file from a modal window. The modal window
I have a page in a modal window where I am displaying a slide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.