【问题标题】:How to display a website in a iframe如何在 iframe 中显示网站
【发布时间】:2015-08-30 01:07:37
【问题描述】:

我正在尝试使用 Razor asp.net 在 iframe 中显示网站,但出现以下错误:拒绝在框架中显示“https://www.google.ro/?gws_rd=cr,ssl&ei=y359VYr9L4PlUeaLg5gG”,因为它将“X-Frame-Options”设置为“同源'。

这是代码:

@{
    ViewBag.Title = "About Us";
}

<script type="text/javascript">
    $(function () {
        $('#myButton').click(function () {
            $('#myFrame').attr('src', "http://www.google.com");
        });
    });
</script>
<iframe id="myFrame"></iframe>
<button id="myButton">
    Refresh IFrame
</button>

【问题讨论】:

    标签: c# asp.net iframe razor


    【解决方案1】:

    您可以使用Google custom search。 它对我很好。 它发送X-Frame-Options: ALLOWALL,允许您将此站点嵌入到您的 IFRAME。请参阅https://productforums.google.com/forum/?hl=en#!category-topic/websearch/how-do-iusing-google-search/pjHnvDST2D4 了解更多信息。

    【讨论】:

      【解决方案2】:

      我通过简单地添加:

      <!DOCTYPE html>
      <html>
      <head>
      <script type="text/javascript"
          src="http://maps.google.com/maps/api/js?sensor=false">
      </script>
      <script type="text/javascript">
        function initialize() {
          var position = new google.maps.LatLng(-34.397, 150.644);
          var myOptions = {
            zoom: 10,
            center: position,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          var map = new google.maps.Map(
              document.getElementById("map_canvas"),
              myOptions);
      
          var marker = new google.maps.Marker({
              position: position,
              map: map,
              title:"This is the place."
          });  
      
          var contentString = 'Hello <strong>World</strong>!';
          var infowindow = new google.maps.InfoWindow({
              content: contentString
          });
      
          google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map,marker);
          });
      
        }
      
      </script>
      </head>
      <body onload="initialize()">
        <div id="map_canvas" style="width:500px; height:500px"></div>
      </body>
      </html>
      

      【讨论】:

        【解决方案3】:

        尝试使用对象标签。

        <!--[if IE]>
        <object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="http://www.google.com">
        <p>backup content</p>
        </object>
        <![endif]-->
        
        <!--[if !IE]> <-->
        <object type="text/html" data="http://www.google.com" style="width:100%; height:100%">
        <p>backup content</p>
        </object>
        <!--> <![endif]-->
        

        编辑:或者您可以使用 jquery 生成它:

        <script>$("#testLoad").load("http://www.google.com/");</script>
        <div id="testLoad"></div>
        

        【讨论】:

          【解决方案4】:

          您尝试显示的页面设置了一个标题,阻止它在 iframe 中显示 - 无法在 iframe 中显示。

          【讨论】:

          • 在 iframe 中显示网站并不是绝对必要的...我只想显示它而不打开另一个标签
          猜你喜欢
          • 1970-01-01
          • 2019-04-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-10-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多