By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

problem with anchor events, please help!!

P: n/a
Hi,

Is there an event that fires when the back or forward button on a
browser is pressed? I need an event to fire when someone clicks the
back or forward button after an anchor has been set.

Thanks so much for reading about my problem!

H

Dec 30 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi Lee,

I mean that when the url hash changes, or in other words, when the hash
property of the location object changes; more specifically, triggered
from either the forward or back button.

I will elaborate from a user perspective:

You enter a page with anchors, and the hyperlinks to the anchors are at
the top of the page. When you click on the hyperlink, it jumps to the
corresponding anchor, and the anchor hash appears in your address bar
(ie #description). Now, when you click on a few anchor links you begin
to build a history. Using your browser, when you click the back button,
you will begin jumping around the various named anchors you visited
previously.

And so, my question is whether there is a way to trigger a function
when the back and forward buttons are used to navigate between the
named anchors.

I appreciate your attention Lee,

H

Dec 31 '05 #2

P: n/a
el****@gmail.com said the following on 12/30/2005 7:45 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<snip>
And so, my question is whether there is a way to trigger a function
when the back and forward buttons are used to navigate between the
named anchors.


You have no way of programatically knowing whether I clicked the
forward/back buttons or not. Nor will you know if I right clicked and
chose "Forward/Backward".

You can only, minimally, know that I am navigating. Not where I went,
where I came from, nor how I choose to get there.

You could try setting a cookie that tracked the history of the page. But
the approach and idea itself lends to failure.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 31 '05 #3

P: n/a
Hi Randy,

I apologize for the mistake when replying, are there consequences to
the way I replied?

Well, let me describe the specific task that I'm trying to accomplish,
maybe you, or others, could lend some clarity to the limits I'm up
against.

I'm building a tool that will allow actionscript developers to use the
browsers forward and back button to trigger events by using the url
hash as the distinguishing identifier. Using the hash will also allow
for bookmarking, so that when a flash page is revisited, or linked, the
actual content that the end user is attempting to share may be directly
visited.

I have this working: http://www.anticipatechange.com/browserSupport/

use the setAnchor button to set the url hash, then use the back and
forward button to observe the functionality I'm talking about.

My problem is that the back and forward events are triggered by a
setInterval function from within flash that is continually checking the
url hash for differences, and so, when a difference is detected it
triggers an event.

I was hoping there was a way for me to trigger a function call when the
url hash changes, but if that's not possible, given the problem, can
you, or anyone else for that matter, think of a solution to this
problem?

I don't like the idea of having to continually check the url, it is a
terrible work around.

Thanks so much for your attention Randy,

H

Dec 31 '05 #4

P: n/a
On 2005-12-30, el****@gmail.com <el****@gmail.com> wrote:
Hi,

Is there an event that fires when the back or forward button on a
browser is pressed? I need an event to fire when someone clicks the
back or forward button after an anchor has been set.


no. such an event could be misused (eg to keep someone on a page when they
want to leave)

you may have to redesign your application to allow history navigation.

Bye.
Jasen
Dec 31 '05 #5

P: n/a
On 2005-12-31, el****@gmail.com <el****@gmail.com> wrote:
Hi Lee,

I mean that when the url hash changes, or in other words, when the hash
property of the location object changes; more specifically, triggered
from either the forward or back button.

I will elaborate from a user perspective:

You enter a page with anchors, and the hyperlinks to the anchors are at
the top of the page. When you click on the hyperlink, it jumps to the
corresponding anchor, and the anchor hash appears in your address bar
(ie #description). Now, when you click on a few anchor links you begin
to build a history. Using your browser, when you click the back button,
you will begin jumping around the various named anchors you visited
previously.

And so, my question is whether there is a way to trigger a function
when the back and forward buttons are used to navigate between the
named anchors.

I appreciate your attention Lee,


ah... that't different. yes it's possible.

you could set an onInterval event which watches location.hash
and acts when it changes.

in some agents it may be possible to use onPropertyChange or watch
to trigger the event instantaneously. whereas setinverval can only
be almost instantaneous.

here's an example (tested in mozilla only, but should be portable)

<html>
<head>
<script language="javascript">

// I find alert irritating... this puts a message in a form field
function msg(msg){
document.forms['info'].elements['message'].value=msg;
}

var oldloc='';

function check(){
if(location.hash != oldloc){
msg("navigation: from:"+oldloc+" to:"+location.hash);
oldloc=location.hash;
}
}

function initialise()
{
setInterval(check,100); // run check every 100 miliseconds
// that is, 10 times every second.
msg("This is a test");
}

</script>
</head>
<body onload="initialise()">

<form name="info">
<input name="message" value="Hello!" type="text" style="width:18em;">
</form>

<a href="#a">to anchor a</a>
<a href="#b">to anchor b</a>
<a href="#c">to anchor c</a>
<a href="#d">to anchor d</a>
<a href="#e">to anchor e</a>
<a href="#f">to anchor f</a>
<a href="#g">to anchor g</a>
<a href="#h">to anchor h</a>
<br>
<a name="a">a</a><br>
<a name="b">b</a><br>
<a name="c">c</a><br>
<a name="d">d</a><br>
<a name="e">e</a><br>
<a name="f">f</a><br>
<a name="g">g</a><br>
<a name="h">h</a><br>

</body>
</html>


--

Bye.
Jasen
Dec 31 '05 #6

P: n/a
On 2005-12-31, el****@gmail.com <el****@gmail.com> wrote:
Hi Randy,

I apologize for the mistake when replying, are there consequences to
the way I replied?
there can be... it's generally a good idea to quote a little of the mesage
you are replying to so that readers can see immediately what you are
replying to. also replying in context can save you typing
I'm building a tool that will allow actionscript developers to use the
browsers forward and back button to trigger events by using the url
hash as the distinguishing identifier. Using the hash will also allow
for bookmarking, so that when a flash page is revisited, or linked, the
actual content that the end user is attempting to share may be directly
visited.
if you're only interested in where they are currently periodicaly checking
location.hash will give that information.
I was hoping there was a way for me to trigger a function call when the
url hash changes, but if that's not possible, given the problem, can
you, or anyone else for that matter, think of a solution to this
problem?
I just tried watch()ing location.hash and it didn't work... so ignore that
part of me previous post.
I don't like the idea of having to continually check the url, it is a
terrible work around.


yes, but it works, and doesn't consume a great amount of their processor's
power
Bye.
Jasen
Dec 31 '05 #7

P: n/a
Hi Jason,

Thanks you so much for your insight into the matter, you've helped me
alot. You've mentioned that onPropertyChange doesn't work with
location.hash, so I will rule that out as a possibility, however, the
code solution you've written is something I'm very interested in
implementing; would you recommend my using the onInterval function in
building a framework that is demanding of a high level in
compatibility?

The solution you've presented is better than the one I'm currently
using, since no document to object communication will be made, meaning,
I can use true delegation patterns, and in affect is the elimination of
the frequent cross scope communication. As I've said though, every new
javascript member I introduce into the framework must be multi agent
friendly.

I appreciate your attention Jasen,

H

Dec 31 '05 #8

P: n/a
Hi Jason,

Thank you so much for your insight into the matter, you've helped me
alot. You've mentioned that onPropertyChange doesn't work with
location.hash, so I will rule that out as a possibility, however, the
code solution you've written is something I'm very interested in
implementing; would you recommend my using the onInterval function in
building a framework that is demanding of a high level in
compatibility?

The solution you've presented is better than the one I'm currently
using, since no document to object communication will be made, meaning,
I can use true delegation patterns, and in affect is the elimination of
the frequent cross scope communication. As I've said though, every new
javascript member I introduce into the framework must be multi agent
friendly.

I appreciate your attention Jasen,

H

Dec 31 '05 #9

P: n/a
On 2005-12-31, el****@gmail.com <el****@gmail.com> wrote:
Hi Jason,

Thanks you so much for your insight into the matter, you've helped me
alot. You've mentioned that onPropertyChange doesn't work with
location.hash,
watch (gecko based age) doesn't work (or I used it incorrectly). I
haven't tried onPropertyChange as I'm not prepared to comply with all
the requirements needed to access the documentation.
so I will rule that out as a possibility, however, the
code solution you've written is something I'm very interested in
implementing; would you recommend my using the onInterval function in
building a framework that is demanding of a high level in
compatibility?
setInterval
AFAIK it's supported by all the popular agents.
The solution you've presented is better than the one I'm currently
using, since no document to object communication will be made, meaning,
I can use true delegation patterns, and in affect is the elimination of
the frequent cross scope communication. As I've said though, every new
javascript member I introduce into the framework must be multi agent
friendly.


There's too many unfamiliar terms in there for me to understand it fully.
I started coding javascript just after easter last year. before that it was
a mix of other (mainly non-00) compiled and interpreted languages.

Bye.
Jasen
Jan 1 '06 #10

P: n/a
Thanks Jasen, you've been a great help.

H

Jan 2 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.