Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access global event object in Firefox

The goal: run some functions on .ajaxStart() but only if fired by a certain event.

The code:

$('#loading_indicator').ajaxStart(function() {
    if(event != null){
            if(event.type == 'hashchange' || event.type == 'DOMContentLoaded'){
                $(this).show();
                $('#acontents').hide();
                $(this).ajaxComplete(function() {
                    $(this).hide();
                    $('#acontents').show();
                    bindClickOnTable();
                    initFilterInput();
                });
            }
    }
});

The problem: This does not work in Firefox. In Internet Explorer and Chrome I can happily access the event object without passing it to the .ajaxStart(function(). In Firefox however, the event object is undefined.

The obvious but incorrect solution: pass the event object to the function. this will not work because it will pass the ajaxStart event and my checks will not work anymore.

The question: How do I make the global event object accessible within this function?

like image 981
Wilgert Avatar asked Nov 04 '22 03:11

Wilgert


1 Answers

You can store event Object in any variable than can use in other function.

Here is the demo : http://jsfiddle.net/cVDbp/

like image 149
Paresh Balar Avatar answered Nov 09 '22 04:11

Paresh Balar