简体   繁体   中英

Code after window.alert executes intermittently

The assumption is window.alert blocks the serial code execution till the user clicks ok.

In my case it misbehaves and sometimes the code below is executed. Noted this when the browser was minimised.

the window.alert is used to bring focus to the application tab if it is out of focus.

Is there any scenario in which the code execution continues after alert is called?.

browser: latest chrome.

code snippet used:

if(!document.hasFocus()){  
  setTimeout(function(){        
        window.alert('Your session is about to expire! Please click OK to return');
  /* Here after alert the whole functionality should be paused. Below console & function will be executed after OK is clicked*/
        console.info('After alert, ishown');
        me.fncExecuteMyFunction('FROM_BROWSER_ALERT');      
    }, 1);

    return false;
}

Thanks,

Anish

Instead of using an alert, you could just use a modal dialog. A div that floats on top of everything else. In this way, you are not dependent on how different browsers handle code execution with alerts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM