简体   繁体   中英

Scrolling inside an iFrame

Here's the deal: I spent 5 hours looking for a good solution for my problem and found many (unfortunately not working, or it was me doing sth wrong).

I have a page, in which I have an iFrame. I do not want to scroll the page to see the iFrame properly. My point is to scroll the iFrame in that page so it would change it's position (page inside iFrame).

What won't work: putting a window scrollTo into a iFrame page code (simply because this page is not mine, so ie: I have my own page and in iFrame I have stackoverflow.com, and I want it to scroll 100px to the right and 500px to the bottom).

I hope you got my point, and will help me to fix it.

Just please, be kind and give me the whole working example with an iFrame. I just can't stand spending any more time on figuring it out... Is it even possible? ...

Pekka is correct - it's not possible. Because the iframe's src is from a different domain, no browser will let code from the parent window access the DOM or window. This is important and intentional. If pages are from different domains, it's entirely possible that a malicious script running in a separate window could cause serious problems in the parent window.

One way to do it is as follows:

 <div style="height: 500px; width: 800px; 
             overflow-y: scroll; overflow-x: hidden;">
 <iframe src="http://www.washingtonpost.com/" 
         style="width: 1500px; height: 2000px;"></iframe>
 </div>

You can modify the CSS to tweak the frame to your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM