Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6941723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:55:20+00:00 2026-05-27T12:55:20+00:00

I have an element inside an <iframe> I’d like to activate using a link

  • 0

I have an element inside an <iframe> I’d like to activate using a link outside the <iframe>.

Example:

<iframe src="iframe.html" id="iframe">
    *inside the iframe*  
    <div id="activate" class="activate">
</iframe>
<a href="#activate" target="iframe">Link</a>

I thought this would work but obviously does nothing because I’m stupid. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:55:21+00:00Added an answer on May 27, 2026 at 12:55 pm

    Framed page (test.html):

    ....... lots of content .... 
    <div id="activate">Inside frame</div>
    

    Page containing the frame (page-containing-frame.html):

    <iframe src="test.html" name="target-iframe"></iframe>
    <a href="test.html#activate"
           target="target-iframe"
           onclick="frames['target-iframe'].document.getElementById('activate')
                    .scrollIntoView();return false">Click</a>
    ^ That's the link. I've split up code over multiple lines for visibility
    

    Explanation

    • The frame has a name attrbute with the value of target-iframe (obviously, you can choose any desired value).
    • The link contains three attributes, each supporting two methods to scroll to a link in the frame:

      1. target="target-iframe" and href="test.html#activate"
        This is the fallback method, in case of an error occurs, or if the user has disabled JavaScript.
        The target of the link is the frame, the href attribute must be the path of the frame, postfixed by the anchor, eg test.hrml#activate. This method will cause the framed page to reload. Also, if the anchor is already at #activate, this method will not work any more.
      2. This is the elegant solution, which shold not fail. The desired frame is accessed through the global frames object (by name, NOT by id, target-iframe). Then, the anchor is selected (document.getElementById('activate').
        Finally, the scrollIntoView method is used to move the element inside the viewport.
        The onclick method ends with return false, so that the default behaviour (ie following the link, causing a page refresh), does not happen.

    Your current code did not work, because of the missing name attribute (target="..." cannot match IDs, only names). Also, #activate is parsed in the context of the current page, so, the link points to page-containing-frame.html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you set an html element to have display: none , the content inside
What a mouthful. Basically I have a parent <div> and inside that an <iframe>
I have something like this: <!doctype html> <html> <body> <iframe id="someFrame"></iframe> </body> </html> And
Say that I have an element inside a div (or any other containing element,
I have a <div> element inside another <div> . I have an onClick event
I have a element as below inside the document, I could get the iframe
I have a span element inside a table td element. The span tag has
I have an input[type=radio] element inside a block container of fixed width. The supporting
I have a scrollview control that has a StackPanel (Orientation=Vertical) UI Element inside of
On Window 's load, every DD element inside Quote_App should have an onCLick event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.