due to XSS restrictions which you can set but cannot read top.location.href if your iframe is in a different domain than the page calling the iframe. If the page you are redirecting to has the same domain name, you can check top.location.href. Thus, the logic, if your code should be canceled, checks if it can access top.location.href and if NOT redirected. put it in a try..catch block to avoid javascript errors when accessing top.location
source share