Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  114] [ 6]  / answers: 1 / hits: 17184  / 15 Years ago, thu, september 17, 2009, 12:00:00

add a hash to url without scrolling page?
with javascript




  1. i open page

  2. i scroll down

  3. i click link that adds a hash (maybe with a value #test) (example: http://www.example.com/#test)

  4. the page MUST not scroll back to the top.



how can this be done?



note:
just checking if it's possible to disable the movement even if there is some tag with id=test
so far the return false; works fine (to support people without javascript), and also to avoid the presence of the id's in the html, but it is not a problem with things like numbers, like 1, 2, 3 (they are not allowed as id's anyway)



all the answers are great, nothing new or groundbreaking, and no solutions on how to break the default functionality, but it will do. :)
thank you for taking the time to answer.


More From » url

 Answers
19

Any hash that isn't present on the page should give you this behaviour. For example, this link points to a non-existant hash on this page. (Link tested with Chrome 2.0 and IE 6 (the only browsers I have available to me at the moment).)



So if your URL is causing you to go to the top of the page, make sure you have nothing on the page whose id or name is that address.


[#98672] Monday, September 14, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradleymoisesy

Total Points: 121
Total Questions: 105
Total Answers: 95

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
bradleymoisesy questions
Wed, Dec 22, 21, 00:00, 3 Years ago
Tue, Jun 1, 21, 00:00, 3 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;