21

I'm tring to embed a webpage in an iframe, but it doesn't work at all. internal pages with relative path are displayed normally. but this simple code doesn't work:

<iframe src="http://www.google.com/"></iframe>

the place that supposed to show the iframe is just empty. i looked in the page source and there is nothing after

How can this be?

Moshe Shaham
  • 15,448
  • 22
  • 74
  • 114

3 Answers3

35

Google uses an X-FRAME-OPTIONS HTTP header to disallow putting their pages in iframes: https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header

Almost all modern browsers will refuse to put pages with this HTTP header in an iframe. There's nothing you can do about that.

Daan
  • 3,403
  • 23
  • 19
3

Because the internal page had do something to prevent to be put in iframe.

Maybe a piece of javascript like that

if (window.top != window.self) {window.top.location = window.self.location;}
horsley
  • 480
  • 4
  • 10
-1

Suppose your url is www.google.com, i.e $url = "www.google.com";

$headerRes = get_headers($url);  //get the header response

foreach($headerRes as $val)
  if($val=="X-Frame-Options: SAMEORIGIN" || $val=="X-Frame-Options: DENY"){
    header("location:".$url); 
    exit; 
  }
//simply redirect to their website instead of showing blank frame

I hope I explained myself good.

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
Sachin Pundir
  • 203
  • 3
  • 6
  • 1
    Neither the question ask for a PHP solution nor does the answer indicate you are using a serverside solution (i.e. PHP) to redirect the user. – Ryan Schumacher Apr 14 '17 at 18:14