我正在尝试使用Jquery来构建iframe,我认为这是通过此代码直接进行的,但它不起作用..
jQuery(document).ready(function() {
$("#opposition a").click(function(e) {
var first_id = $(this).attr('id');
var second_id = $("h1").attr('id');
$("#opposition img").mouseover(function() {
$(this).css('border-width','5px');
});
$("#opposition img").mouseout(function() {
$(this).css('border-width','2px');
});
$.get("compare_proc.php",{
id:first_id,
id2:second_id
});
$("#frame").attr("src", "http://www.google.com/");
e.preventDefault();
});
});
HTML:
<div id="mydiv"><iframe id="frame" src="" width="100%" height="300">
</iframe></div>
<button id="button">Load</button>
答案 0 :(得分:0)
这是因为Google.com正在回复的标题为X-Frame-Options。来自文档:
X-Frame-Options HTTP响应头可用于指示 是否允许浏览器呈现页面中的页面
<frame>
或<iframe>
。站点可以使用它来避免点击劫持, 确保其内容未嵌入其他网站。
并非所有服务器都发送此响应标头(例如demo),这有效:
<div id="mydiv"><iframe id="frame" src="" width="100%" height="300">
</iframe></div>
<button id="button">Load</button>
<script>
$('#button').on('click', function() {
$("#frame").attr("src", "http://wikipedia.com");
});
</script>