Just to be precise, onBlur is a JavaScript event for an item that loses its focus, visibilitychange is what you actually need to detect tab changing.