CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    5

    Scroll to Named Anchor in IFRAME

    Hi,

    I am working on a page that includes an Iframe. Inside this Iframe I dynamically assign named anchors.

    Now, what I want to do is as follows: I want to use a SELECT menu to scroll to the named anchors in the Iframe.
    However, the SELECT menu is not situated in the Iframe source page, but rather in the page containing the Iframe.
    In other words; I've got a page called index.php that contains both the

    coding for the SELECT menu:
    Code:
    <select name='menu' onchange='scroll2anchor();'>
    and the iframe coding:
    Code:
    <IFRAME name="gerechten" src="lijst_gerechten_test.php"></IFRAME>
    The option values in the SELECT menu coincide with the named anchors, and I am using them to determine to which named anchor needs to be scrolled. Thus, selecting option 4 would have to scroll to named anchor 4.

    I tried to use a javascript function that contains:
    Code:
    function scroll2anchor(a) {
     var lok;
     lok = "#"+a;
     document.gerechten.location.href=lok;
    }
    But rather than scrolling to the named anchor in the Iframe, it actually loads the entire page inside the Iframe.

    Can anyone help me out with this issue? If you need more information just let me know.

    Thx in advance!

    With kind regards,

    Oculas

  2. #2
    Join Date
    Jul 2005
    Posts
    5

    Re: Scroll to Named Anchor in IFRAME

    I already solved it.

    I recoded the function as follows:
    Code:
    function scroll2anchor(a) {
    var element = null;
         element = document.getElementById("gerechten");
        
       iframe_src = element.src;
       var src_array=iframe_src.split("#");
       document.getElementById("gerechten").src= src_array[0]+"#"+a;
    
    }
    This works like a charm, both in IE and Firefox

    Regards,

    Oculas
    Last edited by oculas; July 19th, 2005 at 07:06 AM.

  3. #3
    Join Date
    May 2004
    Location
    MN / NJ, United States
    Posts
    768

    Re: Scroll to Named Anchor in IFRAME

    Good job!
    *9-11-01* Never Forget; Never Forgive; Never Relent!
    "If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured