一個例子設置的URL,而不是在src標題,這樣的jQuery可以動態設置的SRC用所需的URL來加載iframe。
//Trying to load the URL dynamically did not work for me
//hence using the title as a workaround
<iframe id="facebookFrame" title="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%xxxxxx%xxxxxx&width=300&colorscheme=light&show_faces=true&border_color&stream=true&header=true&height=590" scrolling="no" frameborder="0" style="border: none; overflow: hidden; width: 300px; height: 590px;"></iframe>
//on click
$("#yourButton").click(function(event) {
$("#facebookFrame").attr("src", $("#facebookFrame").attr("title"));
$("#facebookFrame").removeAttr("title");
});
//using a timer to load the iframe after 2 seconds
window.setTimeout(function() {
$("#facebookFrame").attr("src", $("#facebookFrame").attr("title"));
$("#facebookFrame").removeAttr("title");
}, 2000);
//on user scroll
$(window).bind("scroll", function(event) {
$("#facebookFrame").attr("src", $("#facebookFrame").attr("title"));
$("#facebookFrame").removeAttr("title");
});
是否必須使用XFBML?它可以使用iframe嗎? – 2011-05-06 22:01:39