1
votes

I have an iframe that has a source of /website-policy#privacy but when this loads the iframe stays at the top instead of jumping to the id. Is there anyway without the use of js to make this go to the correct section?

At the moment I have had to use the following jQuery:

iframe.contents().find('html,body').animate({ scrollTop: iframe.contents().find('#privacy').position().top - 10 }, 1);

but this seems rather untidy and I don't want to have to do this each time I have an iframe with a hash-tag in the url

Here is a fiddle of what is happening, as you can see the fancybox is opening up but not jumping to the heading "Jump here"

This is my workaround You may have to click the link twice for the fancybox to appear

1
Maybe this helps you (last answer is without js): stackoverflow.com/questions/3419072/… - twain
don't know how he got that to work - I have enough content below the anchor so it should have jumped to it but seems that the only way I can get the iframe to move to the link is by using javascript - Pete
Can you please post your html part, so i can try local? - twain
@twain, I have added a fiddle - Pete

1 Answers

2
votes

The problem seems to be the iframe preload setting in fancybox. If you set this option to false, it will work as expected:

$('a.fancy').fancybox({
    type: "iframe",
    iframe: {
        preload: false
    }
});