473,396 Members | 1,929 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,396 software developers and data experts.

jump to anchor w/o breaking history

Hello,

I have a page with a vertical list of photos separated with bits of text.
Using page down to view the photos is a bit annoying as it will typically
cut the photos as it only jumps a screenfull at a time.

To work around this I added an anchor just before every photo, so that
the page was organised as follows:

<a name="1" id="1"/>
<img src="foo.jpg"/>
<p>Some text..</p>
<a name="2" id="2"/>
<img src="bar.jpg"/>
<p>Etc..</p>

Then I capture a key, space for instance, and invoke the following
function:

function navigateNext() {
if (!window.location.hash) {
window.location.hash = "#2"
} else {
newItem = parseInt(window.location.hash.substring(1)) + 1
if (document.getElementById(newItem)) {
window.location.hash = "#" + newItem
} else {
window.location.hash = "#1"
}
}
}

This works as a charm, jumping to the next anchor until the end of the
page before starting again. There are two problems, however:

The first (and small one) is that if you have a big monitor you will
fit two pictures in a screenful so that when you hit the end of the
page you will have to press space twice to return to the top.

The second (and much bigger one) is that all this anchor jumping
clutters up the history so that when the user hits the back button
of his browser (and he usually will), he will just jump backwards
through the page. Doh! He would of course expect to get back to
the overview page to browse another series of pictures.

I can't seem to find any solution to these problems, though a back
link might help slightly. Another possibility would be to bounce
the user back to the previous page (the overview) instead of the
start of the page after the last picture.

Good ideas are greatly appreciated!

--
Bjørn
Jan 11 '07 #1
3 6296
Bjorn Nordbo <bn@strangedays.nowrites:
>
The second (and much bigger one) is that all this anchor jumping
clutters up the history so that when the user hits the back button
of his browser (and he usually will), he will just jump backwards
through the page. Doh! He would of course expect to get back to
the overview page to browse another series of pictures.
And this was of course the really easy one: history.go(n).

--
Bjørn
Jan 11 '07 #2
Bjorn Nordbo said the following on 1/11/2007 5:17 PM:
Bjorn Nordbo <bn@strangedays.nowrites:
>The second (and much bigger one) is that all this anchor jumping
clutters up the history so that when the user hits the back button
of his browser (and he usually will), he will just jump backwards
through the page. Doh! He would of course expect to get back to
the overview page to browse another series of pictures.

And this was of course the really easy one: history.go(n).
Instead of an anchor use history.replace(anchor) via the onclick of the
anchor and you don't clutter up the history trail.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 11 '07 #3
Randy Webb <Hi************@aol.comwrites:
Bjorn Nordbo said the following on 1/11/2007 5:17 PM:
>>
And this was of course the really easy one: history.go(n).

Instead of an anchor use history.replace(anchor) via the onclick of the
anchor and you don't clutter up the history trail.
Good idea, that works perfectly in Firefox and Safari, but Opera refuses
to replace the history. Also, the code looks nicer now. :-)

function navigateNext() {
if (!window.location.hash) {
window.location.replace(window.location.href + unescape("#2"))
} else {
newItem = nextItem(window.location.hash)
if (document.getElementById(newItem)) {
window.location.replace(stripHash(window.location) + "#" + newItem)
} else {
window.location.replace(stripHash(window.location) + "#1")
}
}
}

--
Bjørn
Jan 12 '07 #4

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

Similar topics

2
by: Rob | last post by:
Hello all, I have an anchor in my page like <a name-"phase_two"/>. When I load my page I call the function body_onload in the onload event of the body tag. Then I like to jump to this...
1
by: Mel | last post by:
i am reading html pages from files, once i read and display the contect, i want to go to the end of that page that could be several 100 lines long. i need a java script to execute after i placed...
2
by: VB Programmer | last post by:
I created a page which I am using to prevent the user from hitting the BACK button. I'll call it my "Auto Jump" page. When it is called it basically auto-redirects to a page specified in the...
2
by: Robert Wehofer | last post by:
Hello there! How is it possible to jump to an anchor by using ASP.NET? Is it only possible by using JavaScript Code? If so, how has the JavaScript to look like? Thank you in advance, Robert
16
by: darrel | last post by:
I have an anchor on my page: <a name="monkey"></a> I can easily go to this via a redirect, but is there a way to jump to this on postback? -Darrel
10
by: elibol | last post by:
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. ...
6
by: dark.peony | last post by:
Hi, (--1--) I'm trying to find a way to jump to a link (<a href="ref"></a>) in a page that is generated with javascript. The source view of the page only shows the javascript methods. The...
2
by: gvrajkumar | last post by:
Hi We are developing an Ajax based application. In this application the URL is fixed and as user navigates on the application we will change Anchor on the URL so that user can bookmark the url...
1
by: Egbert Teeselink | last post by:
Hi guys, A DOM-related question here, hope it's the right group.. Upon entering a page, i get an onload() event which I'm a happy taker of. Now, if within the same page, the user travels to an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.