2015-06-14 133 views
2

我想在使用Razor asp.net的iframe中顯示網站,但出現以下錯誤:拒絕在框架中顯示'https://www.google.ro/?gws_rd=cr,ssl&ei=y359VYr9L4PlUeaLg5gG',因爲它將'X-框架選項'設置爲'SAMEORIGIN'。如何在iframe中顯示網站

這是代碼:

@{ 
    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> 

回答

1

你正在試圖表明已經設置了禁止它在iframe正在顯示一個標題頁 - 沒有辦法在一個iframe來顯示這一點。

+0

這是完全沒有必要的iframe來顯示網站...我只想顯示,但無法打開另一個選項卡 – Valip

1

嘗試使用對象標籤。

<!--[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> 
+0

同樣的錯誤...... .. – Valip

+0

已更新的答案。 –

0

我通過簡單地添加完成此:

<!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>