如何在会话超时时关闭所有活动的引导模式?

时间:2022-04-21 18:49:12

I need to make a call when the user is idle and passes the session time out that will close all Bootstrap modals. The modals being active are dependent on what the user is doing at the time so I would like to do something that's is all encompassing.

我需要在用户空闲时进行调用,并传递会话时间以关闭所有引导模式。活动的modals取决于用户当时在做什么,所以我想做一些包罗万象的事情。

I tried:

我试着:

$('.modal').modal('toggle');

When the time out occurs but my modals are still there.

当时间发生时,我的情态动词仍然存在。

4 个解决方案

#1


79  

Use the following code:

使用下面的代码:

$('.modal').modal('hide');

Also if you would like to do something if the modal is hidden then you can do this:

如果你想做什么如果模态是隐藏的那么你可以这样做:

$('.modal').on('hidden', function () {
  // write your code
});

#2


5  

The correct answer is missing something vital.

正确的答案是缺少一些重要的东西。

$('.modal').modal('hide') // closes all active pop ups.
$('.modal-backdrop').remove() // removes the grey overlay.

The second line is vital if you want the users to use the page as normal.

如果您希望用户正常使用页面,那么第二行是至关重要的。

#3


0  

This is how i got it working in my project without using any factory or additional code.

这是我在不使用任何工厂或其他代码的情况下,在我的项目中工作的方法。

//hide any open bootstrap modals
  angular.element('.inmodal').hide();

I have a timeout function that emits logout as $rootScope.$emit('logout'); and the listener in my service is as follows:

我有一个超时函数,它将登出作为$rootScope。我的听众如下:

$rootScope.$on('logout', function () {                    
                    //hide any open bootstrap modals
                    angular.element('.inmodal').hide();

                    //do something else here  

                });

If you want to hide any other modals such as angular material dialog ($mdDialog) & sweet alert dialog's use angular.element('.modal-dialog').hide(); & angular.element('.sweet-alert').hide();

如果您想隐藏任何其他的modals,如角材质对话框($mdDialog)和sweet alert对话框使用angular.element('.modal-dialog').hide();& angular.element(.sweet-alert)hide();

I don't know if this is the right approach , but it works for me.

我不知道这是不是正确的方法,但它对我很有效。

#4


-1  

Try this way : $('.modal.in:visible').modal('hide');

试试这个方法:$('. modalin:visible').modal('hide');

#1


79  

Use the following code:

使用下面的代码:

$('.modal').modal('hide');

Also if you would like to do something if the modal is hidden then you can do this:

如果你想做什么如果模态是隐藏的那么你可以这样做:

$('.modal').on('hidden', function () {
  // write your code
});

#2


5  

The correct answer is missing something vital.

正确的答案是缺少一些重要的东西。

$('.modal').modal('hide') // closes all active pop ups.
$('.modal-backdrop').remove() // removes the grey overlay.

The second line is vital if you want the users to use the page as normal.

如果您希望用户正常使用页面,那么第二行是至关重要的。

#3


0  

This is how i got it working in my project without using any factory or additional code.

这是我在不使用任何工厂或其他代码的情况下,在我的项目中工作的方法。

//hide any open bootstrap modals
  angular.element('.inmodal').hide();

I have a timeout function that emits logout as $rootScope.$emit('logout'); and the listener in my service is as follows:

我有一个超时函数,它将登出作为$rootScope。我的听众如下:

$rootScope.$on('logout', function () {                    
                    //hide any open bootstrap modals
                    angular.element('.inmodal').hide();

                    //do something else here  

                });

If you want to hide any other modals such as angular material dialog ($mdDialog) & sweet alert dialog's use angular.element('.modal-dialog').hide(); & angular.element('.sweet-alert').hide();

如果您想隐藏任何其他的modals,如角材质对话框($mdDialog)和sweet alert对话框使用angular.element('.modal-dialog').hide();& angular.element(.sweet-alert)hide();

I don't know if this is the right approach , but it works for me.

我不知道这是不是正确的方法,但它对我很有效。

#4


-1  

Try this way : $('.modal.in:visible').modal('hide');

试试这个方法:$('. modalin:visible').modal('hide');