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

location.hash question

Hi,

Here is my relevant code for an arbitrary page (let's call it PAGE_B):
<body onload="window.location.hash='anchor';">

With this code, if the user goes from PAGE_A to PAGE_B, he will jump to
PAGE_B#anchor after PAGE_B has fully loaded. BUT... if he clicks the
back button, instead of returning to PAGE_A (which is what I want), he
will return to PAGE_B (without the anchor).

Is there any way to change this behavior... perhaps to replace the
anchor of page without touching the history stack?

Any help would be greatly appreciated.

Thanks,
David

Jul 23 '05 #1
1 2552
<so*******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

Here is my relevant code for an arbitrary page (let's call it PAGE_B):
<body onload="window.location.hash='anchor';">

With this code, if the user goes from PAGE_A to PAGE_B, he will jump
to
PAGE_B#anchor after PAGE_B has fully loaded. BUT... if he clicks the
back button, instead of returning to PAGE_A (which is what I want), he
will return to PAGE_B (without the anchor).

Is there any way to change this behavior... perhaps to replace the
anchor of page without touching the history stack?


window.location.replace(window.location.href + '#the_hash');

Depending on your requirements, you may need something more
sophisticated, such as:

window.location.replace(
window.location.href +
(window.location.search ? window.location.search : '') +
'#the_hash'
);

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2

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

Similar topics

1
by: Yimin Rong | last post by:
Does anyone know if there are any browsers where you must specify "#" as a prefix when setting the hash for the location? For example, the following would move to the intro section of the...
18
by: Simula | last post by:
I am developing an HTML javascript application and I want to preserve state in a way that can be book-marked. I chose HTML anchors as a means of preserving state. When the application changes...
7
by: User | last post by:
Hi, A page I have shows a different background colour depending on the hash portion of the url as it is first loaded. For example a link to mysite/mypage#0000FF would result in a page with a blue...
3
by: Stewart | last post by:
Dear javascripters, Through a frustrating afternoon of debugging I appear to have discovered something: Setting location.hash to an empty string in the global namespace (not inside a...
2
by: Dennis Ålund | last post by:
Is it possible to notice a change of window.location.hash without polling? I'm working on a Ajax-platform (yes, inventing the wheel again) and have finished almost everything except the support...
4
by: akdb8r | last post by:
Is there a way for JavaScript to detect when the user changes the URL hash (location.hash)? Thanks in advance! :)
2
by: danep | last post by:
Basically, my problem is exactly as described in the subject. The problem is somewhat intermittent and unpredictable, but the majority of the time if I just have a statement such as ...
4
by: Mikey C | last post by:
Hi Everyone, I understand in many cases, adding to history when updating window.location.hash is a GOOD thing. In my case, I want to update bookmarkability from javascript (post-load), but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.