Click to See Complete Forum and Search --> : Scroll to Named Anchor in IFRAME


oculas
July 19th, 2005, 06:28 AM
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:

<select name='menu' onchange='scroll2anchor();'>


and the iframe coding:

<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:

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

oculas
July 19th, 2005, 06:45 AM
I already solved it.

I recoded the function as follows:

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

Dr. Script
July 19th, 2005, 11:22 AM
Good job!