Skip to content

Commit

Permalink
try to preserve scrolling on iframe reloads if possible
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-src-components-widgets-lively-iframe.js,
  • Loading branch information
onsetsu committed Aug 21, 2024
1 parent cd955e0 commit da64907
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/widgets/lively-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export default class LivelyIFrame extends Morph {
renewIFrameListener() {
lively.removeEventListener('iframe', this.frame, 'load')
lively.addEventListener('iframe', this.frame, 'load', e => {
lively.warn('now2', this.input.value = this.frame.contentWindow.location.href)
try {
this.input.value = this.frame.contentWindow.location.href
} catch (e) {
lively.warn(e, 'changing iframe url')
}
})
}

Expand All @@ -33,7 +37,17 @@ export default class LivelyIFrame extends Morph {
}

updateFrame(url) {
this.frame.src = url;
const frame = this.frame;
let canJustReload = false
try {
canJustReload = frame.contentWindow?.location?.toString?.() === url
} catch (e) {}
if (canJustReload) {
// preserve scrolling
frame.contentWindow.location.reload(true);
} else {
frame.src = url;
}
}

updatePersistence(url) {
Expand Down

0 comments on commit da64907

Please sign in to comment.