[BUGFIX beta] Fix error with $.focus() on Firefox.

Firefox does not support calling `.focus()` if the window itself does not have
focus.

Resolves #3521.