PDA

View Full Version : Linking to <a name> tags in frames.



green
01-17-2007, 05:04 PM
I'm going for this Javascript forum because from the research I've done so far HTML can't solve this problem it seems - though I'd like to be proved wrong.

I have a frameset of 2 side by side 50% 50% size frames. Let's call them LEFT1 and RIGHT1 and they are in FRAMESET1. In RIGHT1 frame there are links to anchor <a name> tags in, say, RIGHT2 in another frameset (FRAMESET2).

The links have to load FRAMESET2 (same proportions as first) but to tags in RIGHT2. This means just loading a new frameset WON'T work because it'll just go to the top of both frames eg. TARGET="_parent". I need to link to points further down in RIGHT2 (while LEFT2 can stay at the top). As you guys know, the - name.htm#tag1 doesn't work. Is there some work around to this presumably age-old problem? :confused: I'd be really happy for some help on this. BY THE WAY - THIS ONLY NEEDS TO WORK IN IE.

jscheuer1
01-17-2007, 05:24 PM
Age-old? First that I've heard of it. Could you supply a demo? Anyways, if you are loading a new frameset into a frame or taking over the entire window with it, either way you should be able to target your named anchor in the the src attribute of the frame in question. If not, then this really is an age old question, just one no one ever asked me before. Example:


<frameset onload="nof5();" cols = "25&#37;, 25%,*">
<frame name="myframe" src ="black.htm" />
<frame src ="black.htm" />
<frame src ="drop_target.htm#bob" />

. . .

Note: FF does have some problems with this but, they are minimal and probably the result of a bug as, it behaves as expected on reload and under other conditions (mostly once the page with the named anchor is cached). IE 7 and Opera 9.01 both behaved as expected regardless of conditions. If this slight problem in FF is enough to bother you, a script workaround is possible.

Added Later:

Here's a good fix for FF:


<script type="text/javascript">
function toname(){
if (location.hash.length>0&&document.getElementsByName(location.hash.replace(/#/,''))[0])
document.getElementsByName(location.hash.replace(/#/,''))[0].scrollIntoView()
}
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", toname, false );
</script>

Put that script on the page with the named anchor on it.

green
01-17-2007, 06:21 PM
Thanks John. OK so first RIGHT1 frame loads a new window (with 2 frames LEFT2 and RIGHT2) not into the same frame. But surely the code: <frame src ="drop_target.htm#bob" /> means tag "bob" will always be loaded so it's at the top - right? I need SEVERAL tags in frame RIGHT2. (Remember: only IE needs to work here.)

Different links load the frameset below into a new window (called all.htm). There are several tags in: "openings.htm" which could be linked to.

<frameset cols="50%, 50%" frameborder=1 border="0">
<frame name="left" src="main_letters.htm" scrolling="yes" />
<frame name="right" src="openings.htm" scrolling="yes" marginwidth="0" marginheight="0" />
<noframes>
</form>
</body>
</noframes>
</frameset>

I hope I'm being clear.

jscheuer1
01-17-2007, 07:13 PM
Thanks John. OK so first RIGHT1 frame loads a new window (with 2 frames LEFT2 and RIGHT2) not into the same frame. But surely the code: <frame src ="drop_target.htm#bob" /> means tag "bob" will always be loaded so it's at the top - right? I need SEVERAL tags in frame RIGHT2. (Remember: only IE needs to work here.)

I hope I'm being clear.

It could be clearer but, basically yes. Named anchors will not load to the top of the page unless there is enough height to the page so that the rest of the frame or window will have something in it. This is true no matter where named anchors are used. If there is not enough content below the named anchor, it will appear as high up in the frame or window as it can while still having content below it. Blank content can be added to the bottom of a page, if desired.

So you can have:


<frame name="main" src="drop_target.htm#bob" />

and even links from elsewhere in the frameset (or I believe even from other open windows) like so:


<a href="some_other.htm#frank" target="main">Some Page</a>

and they will load into the main frame and scroll to the named anchor:


<a name="frank"></a>

if they have it in their body section with content remaining below the named anchor.



In Short: That is the main function of a named anchor.
If its name appears after the hash (#) of the URL and it is located on the page in the URL,
it will be scrolled to as long as space on the page permits.



Notes: The hash followed by the name should be the last item in the URL. And, just in case you don't know, the URL is what you put as the src attribute or href attribute in the above HTML code examples.

green
01-17-2007, 08:28 PM
I have loaded up a sample so you can see what I mean. Sorry if I'm not clear in my explanation.

As you can see the links in Frame1 of frameset test_frames should go to anchors in Frame2 in frameset2. On the one an only link I've just put the following because I don't know where to put the #:
<a href="test_frames2.htm" target="_parent">

What code can I add to link to the different links?
Here's the link to the sample:
http://www.englishspanishlink.com/test_frames

jscheuer1
01-17-2007, 09:38 PM
First off, name attributes cannot start with numbers, they can contain numbers but, must start with letters or underscores - letters are best. You could change them to a1, a2, a3. For this sort of thing, each one should be unique. Browsers will let you get away with starting with numbers sometimes but, other times will not.

Here is where you would put your hash name in the frameset:


<frameset cols="50%, 50%">
<frame name="frameleft2" src="left2.htm">
<frame name="frameright2" src="right2.htm#a3">
<noframes>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p>Esta p&aacute;gina contiene marcos. Se requiere de un navegador de Web
que tolere marcos para ver esta p&aacute;gina.</p>
</body>
</noframes>
</frameset>