Flipkart uses below code in there HTML to prevent any frame loading their site.
function noxfs() {
try {
if (window.top !== window.self) {
document.write = "";
window.top.location = window.self.location;
setTimeout(function() {
document.body.innerHTML = '';
}, 0);
window.self.onload = function() {
document.body.innerHTML = '';
};
}
} catch (err) {
}
}
noxfs();
Here they update the window.top.location with their own location.
Their attempt to do can be intercepted and you can prevent come out of frame, by using below code.
window.onbeforeunload = function(e) {
return 'Any message here.';
};
Here you event handler which get fired before the window removes the DOM of existing page.