Techniques for controlling the scrolling _javascript of IFRAME pages using the Scroll method of iframe window

Source: Internet
Author: User
How do you control the inline iframe scrolling in the page? The method is to use the scroll method of the iframe window:

1, get the Window object of the IFRAME

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

2, get the window Document object of the IFRAME

var doc = iwin.document;

3, invoke the scroll method of the IFrame window object

Iwin.scroll (0,doc.body.scrollheight);

Scroll two parameters for the x,y axis of the rolling volume

Doc.body.scrollHeight is the height of the IFRAME page (contains the part not shown)

An integrated application example is as follows:
Copy Code code as follows:


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>hover test</title>
<style type= "Text/css" >

ul{
Background-color: #ff00ff;
Display:block;
}

. TOC li{
position:relative; Width:10em;
Background-color: #00ff00;
Display:block;
}

Li a {
/*display:block;*//* If shown in block mode, it will fill up the entire parent element space.
Background-color: #0000ff;
/* must make a a block-level element * *

Li a i{
Display:none;
}

Li a:hover{
Text-align:left;
}/* here to add the code just to let IE6 display, no special features, in addition to Text-decoration,color,z-index can write * *

. TOC Li A:hover i{
Display:block;
Width:6em;
Position:absolute;
top:0;
left:100%; /* Here 100% refers to the width of the element li * *
Margin:-1em 0 0 0em;
Padding:1em;
Background: #cde;
border:1px solid red;
Text-align:left;
z-index:10000;
}
</style>

<body>
<iframe id= "iframe1" src= "width=" "height=" ></iframe>

HTML code

<ul class= "TOC" id= "TOC" >
<li><a href= "1.html" >chapter 1<i>in which a dragon is seen</i></a></li>
<li><a href= "2.html" >chapter 1<i>in which a knight is summoned</i></a></li>
<li><a href= "3.html" >chapter 1<i>in which a proncess is disappointed</i></a></li>
<li><a href= "4.html" >chapter 1<i>in which a dragon is seen</i></a></li>
<li><a href= "5.html" >chapter 1<i>in which a dragon is seen</i></a></li>
<li><a href= "6.html" >chapter 1<i>in which a dragon is seen</i></a></li>
<li><a href= "7.html" >chapter 1<i>in which a dragon is seen</i></a></li>
</ul>

<script language= "JavaScript" >
function Getelementabspos (e) {
var t = e.offsettop;
var L = e.offsetleft;
while (E = e.offsetparent) {
T + + e.offsettop;
L + + E.offsetleft;
}

return {left:l,top:t};
}

function GetPosition (obj) {
var left = 0;
var top = 0;

while (obj!= document.body) {
left = Obj.offsetleft;
top = Obj.offsettop;
obj = obj.offsetparent;
}

return to left;
}

var lis = document.getelementsbytagname (' li ');
var iwin = document.getElementById (' iframe1 '). Contentwindow;
var doc = iwin.document;
for (Var i=0;i<lis.length;i++) {
Lis[i].onmouseover = function () {
var Obji = this.childnodes[0].childnodes[1];
Doc.writeln (' <br> ' + obji.innertext + ', ' + getelementabspos document.getElementById (' TOC ')). left);
Doc.writeln (' <br> ' + obji.offsetleft + ', ' + Getelementabspos (Obji). Left + ', ' + obji.offsetwidth+ ', ' + OBJI.STYLE.L EFT);
Doc.writeln (' <br><b> ' + doc.body.scrollHeight + ' </b> ')
Iwin.scroll (0,doc.body.scrollheight);
Iwin.scrollto (10000); Invalid
}
}

</script>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.