Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3755046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:38:18+00:00 2026-05-19T09:38:18+00:00

in my website i set the url adress using window.location.hash = ‘project_name’; but if

  • 0

in my website i set the url adress using

window.location.hash = 'project_name';

but if i want to clean the adress url from any hashes (when i close a project) and i set

window.location.hash = '';

it happens the page scrolls up to the top page

there is any way to clean up the url without any side effect?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:38:19+00:00Added an answer on May 19, 2026 at 9:38 am

    There’s the onhashchange event, but it cannot be cancelled reliably across browsers to prevent scrolling. The best solution is to record the scroll position before changing the hash location and reset it afterwards. For example, the following code will catch a click on any link ― that doesn’t stop propagation ― with a href value of # and prevent the page from scrolling vertically:

    document.onclick = function (evt) {
        var tgt = (evt && evt.target) || event.srcElement,
            scr = document.body.scrollTop;
    
        if (tgt.tagName == "A" && tgt.href.slice(-1) == "#") {
            window.location.href = "#";
            document.body.scrollTop = scr;           
            return false;
        }
    }
    

    If you’re changing the hash through script, you can use the following code:

    var scr = document.body.scrollTop;
    window.location.href = '#';
    document.body.scrollTop = scr;
    

    Either of those methods can be adjusted to avoid scrolling individual elements or scrolling the page horizontally. Note that you can remove the entire hash (including the #) without causing navigation or scrolling in modern browsers by calling the pushState or replaceState functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a Facebook Application, i set the canvas url domain to the website
I have an ASP.NET website set up, and I'm using Google Analytics for page
I am trying to set up a subdomain on my website but i am
I want to set an alert service for my website users for there tasks.
I'm using awesome_nested_set for my central website structure. I want to be able to
I am using php to develop an application, i have different set of url's
I have a website set on a specific domain which is completely separated from
Using Netbeans I'm setting up a MVC-powered website on localhost. I've set up the
I have set up my website to use ASP.NET Membership. it all works fine
I have set up a website here: http://liamwli.co.uk/ggsim On the bottom, there are 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.