Please let me know if you see any website outside which is having the same scenario
what kind of pop up are you getting?
but basic approach is make 2 functions 1 to check
if the there are more then 1 window
if yes call
call another function which handles it.