PDA

View Full Version : Targeting to a frame


bacterozoid
12-01-2002, 12:13 AM
Alright, using JavaScript, I know how to target a link to another frame.

onClick="parent.framename.location='wherever.htm'"

Simple, but instead of telling it to load a document into the frame, I want it to load a page anchor. For one page, I would use this:

onClick="parent.framename.location='wherever.htm#top'"

Well, okie dokie, easy. The catch is that I want it to be a 'universal' link. Basically that whatever page is loaded into the frame, the link will add #top to the end of the URL, sending it to the specified anchor on that page. How do I go about doing this?

Thanks

bacterozoid
12-01-2002, 01:28 AM
Well, nevermind, problem averted!

<a href="#" onClick="parent.main.location.hash='#top'">

I had never heard of that before. Anyone happen to know exactly what it does?

Steven_Smith
12-01-2002, 02:42 AM
Hi, not sure what 'hash' is but instead of using <a href="#" try

<a href="javascript:parent.main.location.hash='#top'">

That way the user doesn't see the "#" when they click.

Steve

bacterozoid
12-01-2002, 03:12 AM
Dumdeda, okie dokie. Thank you. That works as well.

bacterozoid
12-02-2002, 12:57 PM
Here, for anyone looking for what exactly a hash is:

"hash is a property of both the Link and the Location objects and is a string beginning with a hash (#). It specifies an anchor name in an HTTP URL.

Code:
document.write(location.hash)

Output:
#local?email=name@otherco.com

NOTE:

Although the hash property can be set at any time, it is safer to set the href property to change a location"

This from: http://www.devguru.com/Technologies/ecmascript/quickref/location_hash.html