Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break iframe and redirect page with Jquery

How can i understand that my page is being called from iframe and break it with jquery ? Thank you.

like image 398
MonsterMMORPG Avatar asked Sep 11 '11 02:09

MonsterMMORPG


People also ask

Can you redirect from an iframe?

Redirect the page containing your iframe embed Modern browsers will prevent an iframe from changing the location of its parent page for security reasons. Your iframe embed code and JavaScript code will need to be modified to allow this behavior.

How do I stop redirecting iframe?

Use sandbox attribute. <iframe src=”Site_URL” sandbox=””> – Full Protection. <iframe src=”Site_URL” sandbox=”allow-forms allow-scripts”> – Allow form submission and scripts to run.

Which will allow the document to break out of the frame by navigating the top level window?

allow-top-navigation allows the document to break out of the frame by navigating the top-level window.


2 Answers

if (self !== top)
    top.location.replace(self.location.href)

that's how you break out of a frame

like image 178
Joseph Marikle Avatar answered Oct 11 '22 06:10

Joseph Marikle


This can be done in plain Javascript since top and location are both objects attached to the global window object provided in all major browsers.

if (top.location != location){
    location.href = 'http://google.com';
}
like image 40
Joe Avatar answered Oct 11 '22 06:10

Joe