iframe with external page not working

后端 未结 3 955
心在旅途
心在旅途 2020-11-27 22:13

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:

<
相关标签:
3条回答
  • 2020-11-27 22:37

    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;}
    
    0 讨论(0)
  • 2020-11-27 22:49

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题