473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Detecting back/forward button use for fragment identifers

I'm putting together a rather dynamic page (AJAX/all-that-mess).

So... to go between different sorts of content on the page, I have it
set up something like this.
<a href="#10" onclick="loadFragment()"> ... </a>
<a href="#20" onclick="loadFragment()"> ... </a>

where loadFragment is a function which does something based on the #20
which is now appended to the document's .location.

This works fine for bookmarks and links (I have an onLoad handler that
checks the fragment as well) but does nothing for people who want to use
the Back button. Is there any way that I can get an explicit
notification when the document's location changes? Or should I try to
poll document.location for changes?
May 7 '06 #1
3 6230
whapts3 said the following on 5/7/2006 3:42 PM:
I'm putting together a rather dynamic page (AJAX/all-that-mess).

So... to go between different sorts of content on the page, I have it
set up something like this.
<a href="#10" onclick="loadFragment()"> ... </a>
<a href="#20" onclick="loadFragment()"> ... </a>

where loadFragment is a function which does something based on the #20
which is now appended to the document's .location.

This works fine for bookmarks and links (I have an onLoad handler that
checks the fragment as well) but does nothing for people who want to use
the Back button. Is there any way that I can get an explicit
notification when the document's location changes? Or should I try to
poll document.location for changes?


You could try polling it but it won't be reliable and could get messy
with user interaction interrupted. As for the Back button, you didn't
ask so I assume you know that you can not detect when the Back button
was clicked.

Otherwise, you may consider building your own History trail with custom
Back and Forward buttons, not changing the URL at all, and when a user
clicks Back on the browser they go back where they originated.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 7 '06 #2
Randy Webb wrote:
You could try polling it but it won't be reliable and could get messy
with user interaction interrupted.


I've tried polling. It seems to work fairly well in IE6 and FireFox
and... a little bit of Opera, kinda, sorta.

http://fennecfoxen.org/misc/photo/reynolda/

I have a polling function that's operating on a window.setTimeout(); -
the problem is that when Opera (v8.5) visits an image, it leaves the
page and the timeout dies, and it is not resumed when they return.

To help evade this, I've put an operation to restart the polling task
whenever you click on a link, but that still leaves the Back button
broken for Opera after you've visited a picture and you haven't clicked
on another link since. I might evade this further in my next version by
putting the image inline with the page- but still, the user might visit
another site and come back and the loop would not be running. My other
browsers (FireFox and IE6) seem OK -- well, Internet Explorer doesn't
deem anchor-changes worthy of a new history entry, so it solves the
problem in another, roundabout fashion... so...
Is there a way to reliably restart the polling operation when Opera
reloads the page?

Hmm. I guess another option here is to try and detect user-agents and
send Opera something which will force it to refresh every time... I
don't really like the sound of that, though, and I've seen Opera be
extremely stubborn about not-reloading stuff...
May 8 '06 #3
whapts3 wrote:
To help evade this, I've put an operation to restart the polling task
whenever you click on a link, but that still leaves the Back button
broken for Opera after you've visited a picture and you haven't clicked
on another link since.


Or maybe it doesn't. I just tried things again and they seemed to work
so I have no clue what's going on anymore and will try again in the
morning when I'm more awake. :)
May 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bud Zielinski | last post by:
Can someone point me to a script that will allow me to implement a "back button" in an HTA, since there is no history for HTA's. Understand this requires an array, is there any sample code out...
3
by: Nick Tew | last post by:
Hi, Firstly, any help would be gratefully received. Im using several iframes on a single page and would like individual 'back' and 'forward' buttons located in each of the iframes which only...
8
by: Tracey | last post by:
Hi, guys. My application requires functionalities like back and forward navigating button on winforms. And there are many forms linking each other. Each form has a pair of buttons of "Back" and...
1
by: Oenone | last post by:
We have a little piece of JavaScript in one of our client's application which automatically sets the input focus to the first control on the HTML form. This works very nicely, except for in one...
79
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
4
by: John | last post by:
Hi everybody, for my web-application (it must currently work only under IE6) I have a servlet that intercepts user's HTTP GET requests for a typical search result page, which contains a paging...
1
by: annir | last post by:
Hi Guys, I used VB.net 2005. In my project I used Drivelistbox, Dirlistbox and Filelistbox so that I can access the drives that I have. I have these problem about the back and forward button,...
3
oranoos3000
by: oranoos3000 | last post by:
hi i'm a beginer javascript would you please help me i d like to findout this page has next page or previous page in history object i use this line of code if(window.history.length>0) and with...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.