问题
On my site I have a fancybox that contains the contents of a hidden <div>
on the page. This hidden <div>
contains a link to an external site.
Is it possible to have this link open in the already open fancybox?
The code I currently have is as follows:
$("#lightbox-link").fancybox({
'scrolling' : 'no',
'width': 5000,
'height': 2000,
'onComplete': function() {
$('a#yes').click(function() {
$.cookie("survey", "dismissed", {expires: 365});
$.fancybox.close();
});
$('a#no').click(function() {
$.cookie("survey", "big-snooze", {expires: 14});
$.fancybox.close();
});
$('a#later').click(function() {
$.cookie("survey", "snooze", {expires: 1});
$.fancybox.close();
});
},
'content' : $("#lightbox-content").html()
});
Thanks!
回答1:
Fancybox's built-in 'href' attribute loads content relative to the current website. As a result loading an external web page shows missing graphics. I came up with the following solution using an iframe. The transition to the external website appears nice and smooth.
<script type="text/javascript">
$(function () { //jquery onload
$.fancybox('<div id="myfancy"><a href="#" onclick="javascript:openlink(\'http://www.cleversavers.com\');">Click me</a></div>'
, {});
});
function openlink(url) {
$.fancybox('<iframe id="myi" src="' + url + '" frameborder="0" height="400" width="600" />', {});
}
</script>
来源:https://stackoverflow.com/questions/5389412/fancybox-opening-a-link-inside-a-fancybox-into-the-same-fancybox