Overcoming “Display forbidden by X-Frame-Options”

后端 未结 26 2207
梦谈多话
梦谈多话 2020-11-21 06:31

I\'m writing a tiny webpage whose purpose is to frame a few other pages, simply to consolidate them into a single browser window for ease of viewing. A few of the pages I\'

相关标签:
26条回答
  • 2020-11-21 07:34

    target='_parent'

    Using Kevin Vella's idea, I tried adding that attribute to form elements made by PayPal's button generator. Worked for me so that Paypal does not open in a new browser window/tab.

    0 讨论(0)
  • 2020-11-21 07:34

    I'm not sure how relevant it is, but I built a work-around to this. On my site, I wanted to display link in a modal window that contained an iframe which loads the URL.

    What I did is, I linked the click event of the link to this javascript function. All this does is make a request to a PHP file that checks the URL headers for X-FRAME-Options before deciding whether to load the URL within the modal window or to redirect.

    Here's the function:

      function opentheater(link, title){
            $.get( "url_origin_helper.php?url="+encodeURIComponent(link), function( data ) {
      if(data == "ya"){
          $(".modal-title").html("<h3 style='color:480060;'>"+title+"&nbsp;&nbsp;&nbsp;<small>"+link+"</small></h3>");
            $("#linkcontent").attr("src", link);
            $("#myModal").modal("show");
      }
      else{
          window.location.href = link;
          //alert(data);
      }
    });
    
    
            }
    

    Here's the PHP file code that checks for it:

    <?php
    $url = rawurldecode($_REQUEST['url']);
    $header = get_headers($url, 1);
    if(array_key_exists("X-Frame-Options", $header)){
        echo "nein";
    }
    else{
        echo "ya";
    }
    
    
    ?>
    

    Hope this helps.

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