Overcoming “Display forbidden by X-Frame-Options”

后端 未结 26 2951
梦谈多话
梦谈多话 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

    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("

    "+title+"   "+link+"

    "); $("#linkcontent").attr("src", link); $("#myModal").modal("show"); } else{ window.location.href = link; //alert(data); } }); }

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

    
    

    Hope this helps.

提交回复
热议问题