if (window.top !== window.self) window.top.location.replace(window.self.location.href);
Simples:
if (window.top !== window.self) window.top.location.replace(window.self.location.href);