Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent my site page to be loaded via 3rd party site frame of iFrame

How can I find out that my page is embedded as a frame to other site during page loading? I guess referrer request header can't help me here? Thanks.

like image 392
Andriy Kopachevskyy Avatar asked May 24 '10 11:05

Andriy Kopachevskyy


People also ask

How do I restrict an iframe?

Thankfully, the ability to restrict iframes is supported by IE 10, Firefox, Chrome, and Safari. It's called the sandbox attribute. Just adding the sandbox attribute is enough to severely lock down an iframe.

How do I stop a page from being Iframed?

There are two primary methods: 1.) Sending an X-Frame-Options HTTP response header that instructs the browser to disable framing from other domains. An example of using PHP to send the X-Frame-Options header.

Can I hide content inside an iframe from an external domain?

Yes totally doable. Once you assign the parameter to a var, you could then do anything you want… like a hide() on an element. Here is a stack solution.


1 Answers

You cannot check it from the server's side, but you can use javascript to detect it after the page has loaded. Compare top and self, if they're not identical, you are in a frame.

Additionally, some modern browsers respect the X-FRAME-OPTIONS header, that can have two values:

  • DENY – prevents the page from being rendered if it is contained in a frame
  • SAMEORIGIN – same as above, unless the page belongs to the same domain as the top-level frameset holder.

Users include Google's Picasa, that cannot be embedded in a frame.

Browsers that support the header, with the minimum version:

  • IE8 and IE9
  • Opera 10.50
  • Safari 4
  • Chrome 4.1.249.1042
  • Firefox 3.6.9 (older versions with NoScript)
like image 148
Maerlyn Avatar answered Sep 29 '22 09:09

Maerlyn