Scenario:
- Parent page a contains IFRAME page B,
- Page B has a long content, and the browser cannot display a full screen or two.
- On page B, there are Directories connected to list1 and list2 at the front of the page. Click list1 or list2 to scroll down to content1 or content2. That is, you need to use the anchor Connection Mechanism on the same page.
Solution:
- The directory connection in the IFRAME subpage is clicked and the related height is passed to the top window.
- The scrolltop attribute of the document is changed in the top window to scroll the page to the response location.
Implementation:
IFRAMEPage-relatedCodeAs follows:
In setwindowscrolltop, the height plus 100 is the distance between the parent page and the top of the iframe B page.
<Ul> <Li> <a href = "javascript: setwindowscrolltop (top, document. getelementbyid ('Id _ content1 '). offsettop + 100); "> <strong> 1 </strong> list1 </a> </LI> <Li> <a href = "javascript: setwindowscrolltop (top, document. getelementbyid ('Id _ content2 '). offsettop + 100); "> <strong> 2 </strong> list2 </a> </LI> </Ul> ....... <Div id = "id_content1"> 1 content1 </div> <Div id = "id_content2"> 2 content2 </div> |
Related JSCode:
Function setwindowscrolltop (Win, topheight)
{
If(win.document.doc umentelement)
{
Win.document.doc umentelement. scrolltop = topheight;
}
If(win.doc ument. Body ){
Win.doc ument. Body. scrolltop = topheight;
}
}
Appendix:Ordinary page anchor:
This issue has already been discussed on the Internet. In general, the implementation of the anchor is based on the browser's support for # name in the URL. And closely related to tags <A>
<A href = "# content1"> list1 </a>
<A href = "# content2"> list2 </a>
...
<A name = "content1" id = "content1"> </a>
Content1...
<A name = "content1" id = "content1"> </a>
content1...