如何在彈出div中加載iframe內容。 popup div會在每個鏈接點擊每個鏈接 時打開,頁面url會加載到iframe href裏面的popup div。如何在Popup div中加載iframe內容?
$(document).ready(function(){
$(".openpop").click(function(){
var x = $(this).attr('href');
alert(x);
y = x.replace('#', '');
alert(y);
$(".popup").toggle();
$("iframe").attr("href", y);
});
$(".close").click(function(){
$(this).parent().fadeOut("slow");
});
});
HTML
<a class="openpop" href="#http://www.google.com">Link 1</a>
<a class="openpop" href="#http://www.yahoo.com">Link 2</a>
<a class="openpop" href="#http://www.w3schools.com">Link 3</a>
<div class="wrapper">
<div class="popup">
<iframe src="">
<p>Your browser does not support iframes.</p>
</iframe>
<a href="#" class="close">X</a></div>
</div>
會很高興得到一個jsfiddle更好的理解 – Dwza 2014-09-11 07:43:23
iframe沒有href,它應該是src屬性,$(「iframe」)。attr(「src」,y);然後x-frame-options會打擾它。 – SSA 2014-09-11 07:43:36