I am using fancybox.js version 2.1.3 to place external content into an iframe. I am doing this by placing the url followed by a div id (e.g. http://somesite.com#about), this seems to work however the problem is I have not found away to stop fancybox from scrolling. preventing scrolling is necessary since i will be placing several div ids on the same external page and then placing them in iframes with fancybox, and i do not want to give the viewer the ability to scroll down within the iframe to view other div ids on this external page.
//fancybox window script
$(document).ready(function() {
$(".various").fancybox({
type :'iframe',
scrolling : 'no',
maxWidth : 800,
maxHeight : 400,
fitToView : true,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none',
});
});
You can disable the scrolling by using a helper as follows:
Why don't you load only the fragment you need rather than the whole document? In that way, you don't need to prevent the scrolling.
If that is an option, you would need to change the way you are loading the file ... a sort of ajax method would work better instead of iframe.
I suggest to use jQuery
.load()
to pull only the requested innerdiv
referenced by itsID
.... so if you are targetinghref="http://somesite.com#about"
for instance, then we would need to call$("#targetContainer").load("http://somesite.com #about");
In order to achieve that, we would need to split the
hash
(#about
) from theurl
to pass the proper format into the.load()
method (notice the space between theurl
and thehash
) ... so having this html... this script should work :
See this working DEMO. The first link pulls the whole file so scroll bars appear while the following only the requested fragment.
NOTE : Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request cannot successfully retrieve data from a different domain, subdomain, or protocol.
BTW,
.on()
requires jQuery 1.7+You can simply edit Fancybox file "jquery.fancybox.js".
Change:
into this:
Checked for Fancybox 2.1.5.
Very easy: just add
And the scroll bars are gone!