jackhao
jackhao

Reputation: 3817

Trigger something only if the tab is not active

I'm using function

$(window).on("blur focus", function(e) {
    var prevType = $(this).data("prevType"); // getting identifier to check by
    if (prevType != e.type) {   //  reduce double fire issues by checking identifier
        switch (e.type) {
            case "blur":
                flashTitle(from + " messaged you", 500);
                break;
            case "focus":
                cancelFlashTitle();
                break;
        }
    }
    $(this).data("prevType", e.type); // reset identifier
})

I want the flash title triggered ONLY when the user is not looking at the tab. Means like the tab is not focused now. Right now the flash title triggered only when I focus the tab first and then leave(blur) it.

Any ideas? Thank you :-)

Upvotes: 0

Views: 165

Answers (1)

Bobogoobo
Bobogoobo

Reputation: 49

It sounds like you would want to flash the title upon getting a new message if the tab is not focused, since the message is the event that's happening, and then cancel any flashing on focus.

Upvotes: 1

Related Questions