Reputation: 43
I am trying to load , http://www.flipkart.com , in a frame . But when it loads , my webpage is replaced with , flipkart home page.
To clarify , window.location.href is changed to flipkart.com .
Can I track this event of redirecting means , like can I open a dialog box - saying 1. Stay on this page . 2. Leave this page .
Upvotes: 1
Views: 1265
Reputation: 1183
flipkart iframe hack trick
you can force flipkart to stay within iframe using sandbox attribute (with allow forms). however there are some limitations like js wont work.
http://www.w3schools.com/tags/att_iframe_sandbox.asp
Upvotes: 1
Reputation: 610
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.
Upvotes: 0
Reputation: 13755
Nope, sites have this as a prevention from loading them in an iframe (short of asking your users to disable javascript)
Upvotes: 1