I recently came across an HTML document that includes an iframe towards the bottom of its content.
Specifically, the iframe is embedding a Google Spreadsheet, using the following code:
<iframe id="gsheet-group" width="100%" height="400" src="https://docs.google.com/spreadsheets/d/<!----DOCUMENT_KEY----->/edit?usp=sharing&rm=minimal&gid=0&single=true&widget=false&chrome=false&headers=false">Loading sheet..</iframe>
It seems like the iframe may contain some javascript that triggers the parent window to scroll to the top under certain conditions, such as when the content is fully loaded or when it is navigated in specific ways. This behavior persists even if the iframe is nested within another iframe.
If I'm unable to directly edit the source code of the iframe, is there a way to prevent the parent window from being affected by the javascript inside the embedded iframe?
My Attempts So Far
I appreciate the suggestions provided by other users, but unfortunately none of them have resolved this issue:
- Adding
to thesandbox="allow-scripts allow-forms allow-pointer-lock allow-same-origin"
<iframe>
element (to removeallow-top-navigation
; @CBroe). - Attempting to override
window.scrollTo
(@Ryano) - Placing the iframe within a separate iframe (@Ryano)