SmartDev SmartDev - 1 year ago 88
Javascript Question

Displaying another website in an iframe

When I use an iframe it is not displaying. Does anyone know an alternative way to display other website on my webpage, using either iframe or div. (Or simple JavaScript, that would be really great.)

I have tried an iframe: Doesn't work

I tried

: Doesn't work.

Any ideas?

Answer Source

If a simple <iframe> isn't working then there isn't any way of doing it in Javascript either. The most likely reason for the iframe not working is because the target site is sending a header to prevent other sites iframing it:

X-Frame-Options: DENY

A lot of sites will do this to prevent a common vulnerability known as UI Redressing or Click Hijacking. Some sites will also include some frame busting Javascript as a backup security measure to the HTTP header.

From MDN:

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> or <iframe>. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download