Go to anchor tag without displaying hashtag in url

I am currently using jQuery to load a page with a specific hashtag (via the onload function in the body class) when the user clicks on the message header. Obviously, the hashtag appears in the url. I was wondering if there is a way to hide the hashtag from cluttering the URL. There were some searches and did not come up much.

 function goToAnchor() { location.href = "#post"; } 
+6
source share
3 answers

As shown here: http://djpate.com/2009/10/07/animated-scroll-to-anchorid-function-with-jquery/

 function goToByScroll(id){ $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow'); } 

Just pass in the id of the item you want to scroll through.

+21
source

You can bind the click event with this particular type of binding and prevent it by default:

 $('.anchorClass').on('click', function(e) { e.preventDefault(); // rest of stuff }); 

“The rest” means looking for a kind of plugin or code that jumps to the page. If you want it to move smoothly forward, there is a fairly popular scrollTo plugin. Perhaps even the scrollTo plugin will take care of the default prevention.

[update]

Jeff's suggestion (assuming it works) is “the rest of the material” and all the more useful of the two answers. ;-) But preventing default is still important.

+6
source

I think you can just use the .htaccess file. There you can make some URLs at the same address.

For example, fff.com/fff and fff.com and fff.com#anchor may appear as fff.com in the browser tab.

0
source

Source: https://habr.com/ru/post/913160/


All Articles