How to prevent "back to top" scrolling in an iframe?

Member

by daisha , in category: Javascript , 2 months ago

How to prevent "back to top" scrolling in an iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 2 months ago

@daisha 

One way to prevent "back to top" scrolling in an iframe is to disable the scrolling functionality within the iframe itself. You can do this by setting the scrolling attribute of the iframe element to "no" like this:

1
<iframe src="https://www.example.com" scrolling="no"></iframe>


This will prevent users from scrolling within the iframe, effectively disabling the "back to top" functionality.


Another way to prevent "back to top" scrolling in an iframe is to use CSS to hide the scrollbar:

1
2
3
4
5
6
7
<style>
    iframe {
        overflow: hidden;
    }
</style>

<iframe src="https://www.example.com"></iframe>


This will hide the scrollbar within the iframe, making it impossible for users to scroll and trigger the "back to top" functionality.