Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if website is loadable in iframe

I need to check, if website in iframe is loaded properly. On my website, users can POST custom website, which will show them in iframe. But some websites are protected from insert to iframe (such as google or facebook).

How can I check, if is website loadable in iframe and can be used in iframe?

PS: I haven't show any code, because I have no code and no idea how to do it. (My website runs on Java, so no Apache or PHP).

like image 713
debute Avatar asked May 12 '14 06:05

debute


People also ask

How do I know if a website is loaded in iframe?

In short, to check if a page is in an iframe, you need to compare the object's location with the window object's parent location. If they are equal, then the page is not in an iframe; otherwise, a page is in an iframe.

How do I allow a website to load an iframe?

To enable the ability to load the site in an iframe: In the left panel, click Settings, and then click Site SSL. Click the Allow site to be loaded in an iframe toggle.

How do I check if an iframe exists?

If you wish to check if there is any iframe at all, you could use getElementsByTagName('iframe'). To make live a little easier, you can take a look at jQuery. This is a Javascript library that helps you to create DOM objects and/or find them in the DOM tree.

Does iframe block page load?

Whereas iframes are typically used to include one HTML page within another, the Script in Iframe technique leverages them to load JavaScript without blocking, as shown by the Script in Iframe example.


1 Answers

Check HTTP response header for X-Frame-Options. Facebook sends X-Frame-Options=DENY, which means "The page cannot be displayed in a frame, regardless of the site attempting to do so."

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object>. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

Check this: Accessing the web page's HTTP Headers in JavaScript

like image 177
Chankey Pathak Avatar answered Sep 23 '22 10:09

Chankey Pathak