0

iFrame and scrollIntoView does not work

asked 2020-01-06 20:15:28 +0800

andij62 gravatar image andij62
315 1 7

Hello everybody,

first of all i wish everyone a happy new year. Now my problem...

I have integrated an input form in an iframe on a foreign page. After checking the input in the controller, I would like to bring the beginning of the iframe back into the display area, but Clients.scrollIntoView doesn't work.

How can I scroll the parent window up so far that the beginning of the iframe comes back in the visible area?

Thank you for your help! Andi

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-01-07 11:24:34 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2020-01-07 11:25:55 +0800

I'd say scroll into view works, it just doesn't do what you expect. My guess: it can only affect the scroll position inside the iframe, if the iframe doesn't have a scrollbar, then there's nothing to scroll, and it won't change the scroll position of the outside page. You didn't provide any details on how it "doesn't work" on your side. If you have any error messages or description of the failing behavior that might help as well.

My idea would be to tell the outer page to update the scroll position. E.g. using the web api window.postMessage() which is dedicated to cross origin inter window/frame communication.

However without your actual code it's hard to perform tests dedicated to your actual problem, and suggest something more concrete.

link publish delete flag offensive edit
0

answered 2020-01-07 19:12:48 +0800

andij62 gravatar image andij62
315 1 7

You're right, the iframe doesn't have a scrollbar, then there's nothing to scroll! The scroll position of the outside page would have to be changed. I found a very simple solution to scroll the outside page by inserting an input field at the beginning of the iframes and focusing on it. Thus the beginning of the iframe comes into view again.

link publish delete flag offensive edit

Comments

sounds like a feasible hack, thanks for sharing (let's hope it works cross browser - my first suspect woudl be IOS safari)

cor3000 ( 2020-01-08 12:13:46 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-01-06 20:15:28 +0800

Seen: 14 times

Last updated: Jan 07 '20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More