IFRAME long page anchor

Source: Internet
Author: User

Scenario:

    1. Parent page a contains IFRAME page B,
    2. Page B has a long content, and the browser cannot display a full screen or two.
    3. 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:

    1. The directory connection in the IFRAME subpage is clicked and the related height is passed to the top window.
    2. 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...

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.