Home > Web Front-end > JS Tutorial > Use the scroll method of iframe window to control iframe page scrolling_javascript skills

Use the scroll method of iframe window to control iframe page scrolling_javascript skills

WBOY
Release: 2016-05-16 16:56:50
Original
1884 people have browsed it

How to control the scrolling of embedded iframe in the page? The method is to use the scroll method of iframe window:

1. Get the window object of iframe

var iwin = document.getElementById('iframe1').contentWindow;

2. Get the window document object of the iframe

var doc = iwin.document;

3. Call the scroll method of the iframe window object

iwin.scroll(0,doc.body. scrollHeight);

The two parameters of scroll are the scrolling amount of the x and y axes

doc.body.scrollHeight is the height of the iframe page (including the undisplayed part)

A comprehensive application example is as follows:

Copy code The code is as follows:





hover test