← Back to home
Planda Blogs

Planda Blogs

.scrollIntoView() inside iframe causes outside page to scroll


As I’ve found with many CSS problems, giving up looking for the perfect solution was the most efficient and worthwhile way to go. After a few hours of searching the internet, reading posts about iframes and scrollIntoView, and trying different fixes, I decided that the best way to proceed was to disable scrolling for the calendar on the page with the iframe.

Here are the things I’ve tried in the process.

1. Finding a CSS solution [Fail]

2. Using Javascript [Fail]

3. Option to disable scroll on my calendar [Pass]

Added a prop to disable scrolling for the calendar. The seems like a reasonable thing to add in the first place, and was quite simple to implement. The page showed in the iframe has a specific query parameter that indicates it is in demo mode, so I disabled scrolling in the calendar based on if that parameter was in the query.

Final thoughts

My current method still seems a bit hacky, since involving Next.js’ router in the first place seems a bit much for a seemingly simple problem. However, what works works, and I don’t have more time to spend on this issue. I did learn more about iframes and scrolling via Javascript through this process, which I am happy about.

https://stackoverflow.com/questions/48634459/scrollintoview-block-vs-inline/ https://stackoverflow.com/questions/56688002/javascript-scrollintoview-only-in-immediate-parent/ https://stackoverflow.com/questions/20956663/scrollintoview-to-apply-to-iframe-only/ https://stackoverflow.com/questions/30809916/how-to-prevent-iframe-actions-from-causing-outer-page-to-scroll-to-it/

Next steps for Planda