How to remove the # when you click on the link to the anchor?

Tell: there is a page on her block #block-1. When I pass the link anchor on the page Anchor in the address bar is not prescribed. But if I go to another page, the address bar is written: www.simple-site.ru/#block-1

How to remove #block-1 from the address bar?

Read more:
So. On the main page there is a block
<div id="block">...</div>.
On another page there is a link-an anchor for the block
<a href="index.html#block"> link </a>.
The result should be:
Click the link =>
opening the main page on the block <div id="block"></div> =>
Write in the address bar, only the address of the site (i.e. remove #block)
July 2nd 19 at 17:06
2 answers
July 2nd 19 at 17:08
To save the current address into a variable and in the transition to replace.
It is possible an example? - Kennedi_Wiza24 commented on July 2nd 19 at 17:11
var current = window.location.href
link.onclick = function (e) {
e.preventDefault();
 window.location.href = current
}
- Shaina commented on July 2nd 19 at 17:14
: I'm doing wrong:
$(".menu-bttn-back a").click(function(){
 var current = window.location.href
 link.onclick = function (e) {
e.preventDefault();
 window.location.href = current
}
 });


Because I failed - Kennedi_Wiza24 commented on July 2nd 19 at 17:17
: Or I do not understand how to attach this function to the button( - Kennedi_Wiza24 commented on July 2nd 19 at 17:20
var current = window.location.href
$(".menu-bttn-back a").click(function(){
window.location.href = current
return false
}); - Shaina commented on July 2nd 19 at 17:23
: Under this option, it does not go to the page and it just reloads - Kennedi_Wiza24 commented on July 2nd 19 at 17:26
: Try window.location.hash = "" - Shaina commented on July 2nd 19 at 17:29
: I do not either. In the address bar attribute in "" - Kennedi_Wiza24 commented on July 2nd 19 at 17:32
In the address of the buildings should remain the address and # - Shaina commented on July 2nd 19 at 17:35
: Yes and still is! - Kennedi_Wiza24 commented on July 2nd 19 at 17:38
July 2nd 19 at 17:10
$('a').on('click', function(e) {
 var href = this.getAttribute('href');
 var myHref = href.split('#');

e.preventDefault();
 window.location.href = myHref[0];
});
It's cool. But he did not move to block the anchor - Kennedi_Wiza24 commented on July 2nd 19 at 17:13
: You decide what you need. go to the unit with anchor or remove the anchor. Or you CNC JS decided to build? - Shaina commented on July 2nd 19 at 17:16
I need to go back to the page with the block on the other page and remove the # from the address bar - Kennedi_Wiza24 commented on July 2nd 19 at 17:19
: Nothing is clear. - Kennedi_Wiza24 commented on July 2nd 19 at 17:22
: So. on the main page there is a block <div id="block">...</div>. On another page there is a link-an anchor on the block <a href="index.html#block"> link </a>.
The result should be: link Click => opening the main page on the block <div id="block"></div> => Write in the address bar, only the address of the site (i.e. remove #block) - Shaina commented on July 2nd 19 at 17:25
: it is unlikely that this can be done, you can put e.preventDefault(); and will not be #for block but then accordingly there will be no transition - Kennedi_Wiza24 commented on July 2nd 19 at 17:28
Read about the history API - replacestate will () is what you need. - Shaina commented on July 2nd 19 at 17:31
: Thank you so much! - Kennedi_Wiza24 commented on July 2nd 19 at 17:34

Find more questions by tags HTMLJavaScript