davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.
https://iframe-resizer.com
Other
6.62k stars 977 forks source link

Back button not working with inPageLinks with workaround #1286

Closed kevinkaske closed 2 days ago

kevinkaske commented 3 days ago

When enabling inPageLinks during initialization, the anchor links work but the back button takes you to the previous page (the page in your history before the page that contains the iframe)

Expected behavior: Take you to the previous spot on the parent page where the link was clicked.

Workaround: I added the following to the child page to add the hash to the parent page history. I also added the class "samepagelink" to make assigning the javascript easier. This adds the same hash from the child page link to the parent page history.

    document.addEventListener("DOMContentLoaded", function() {      
        var elements = document.getElementsByClassName("samepagelink");

        Array.from(elements).forEach(function (anchor) {
            anchor.addEventListener("click", function (event) {
                window.parent.location.hash = anchor.hash;
            });
        });
    });
davidjbradshaw commented 3 days ago

Interesting idea. Will give it some though on how to integrate it to the main code base.

davidjbradshaw commented 2 days ago

This was a one line fix that should have been there from the start. Thanks for the idea. It will be included in the next release.