"I think in most cases this is not possible in just JS." . . . .