Why donβt you download only the fragment that you need, and not the entire document? This way you do not need to prevent scrolling.
If this is an option, you will need to change the way the file is loaded ... the look of the ajax method will work better than the iframe.
I suggest using jQuery .load() to pull out only the requested inner div referenced by its ID .... so if you call href="http://somesite.com#about" , for example, then we need to call $("#targetContainer").load("http://somesite.com #about");
To achieve this, we need to split hash ( #about ) into url in order to pass the correct format to the .load() method (note the space between url and hash ) ... so having this html
<a class="various" href="http:
... this script should work:
// open only selected div (hash) var thisHref, thisHash; $(".various").on("click", function() { thisHref = this.href.split("#")[0]; thisHash = this.href.split("#")[1]; targetContent = $("<div />").load(thisHref + " #" + thisHash); $.fancybox(targetContent, { maxWidth: 800, maxHeight: 400, fitToView: true, width: '70%', height: '70%', autoSize: false, closeClick: false, openEffect: 'none', closeEffect: 'none' }); // fancybox return false; // prevent default }); // on
See this working demo . The first link pulls the entire file, so scrollbars will appear, while the next only 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 another domain, subdomain, or protocol.
BTW, .on() requires jQuery .on()