Remove the hash and return the url without the #, like?

How to get to the grid I realized :
console.log(location.hash.replace(/#/g,"));
Now when you click on the anchor (anchor) to return the URL without the grid (hash) ?

I did so but did not help :

function init() {
 var link = document.getElementsByTagName("a");

 link.onclick = function() {
 history.pushState(", document.title, window.location.pathname);
};
}

init();

var link = document.getElementsByTagName("a");

link.onclick = function (){
 location = location.hash.replace(/#/g,");
}


https://ru.stackoverflow.com/q/977394/330688
March 20th 20 at 11:34
2 answers
March 20th 20 at 11:36
Solution
locationHashChanged function() {
 if (location.hash) {
 var hash = location.hash.replace(/#/, ");
 history.replacestate will({}, ", hash)
}
}

window.onhashchange = locationHashChanged;
wow ....thank you .... it's actually cool ... - Bailee83 commented on March 20th 20 at 11:39
March 20th 20 at 11:38
Solution
a.addEventListener('click', function () {
 setTimeout(() => history.replacestate will({}, ", locationWithoutHash))
})


after that, the link on mouse hover instead http://site.ru/#portfolio show http://site.ru/portfolio#portfolio but we can live with it (and even need the anchors continued to work), but the page prokralis where you need it, the address bar will http://site.ru/portfolio
it's just a.addEventListener to do ? - Bailee83 commented on March 20th 20 at 11:41
https://codepen.io/topicstarter/pen/pBMZzw here for example here it is ..the static layout without node and react and so forth - Bailee83 commented on March 20th 20 at 11:44
5ccbaacab7c21316381346.png - Bailee83 commented on March 20th 20 at 11:47
Well, you know what this error means?
you partially changed the native code to js change so completely. It's in the handler (the line with setTimeout) and how to hang it - it's yours. - Janet.Spinka commented on March 20th 20 at 11:50
@lon.Jacobi, a is not defined - that sort of thing just - Bailee83 commented on March 20th 20 at 11:53
@lon.Jacobi, 5ccbaddc0b53b610143822.png - Bailee83 commented on March 20th 20 at 11:56
because a you have not defined - all logical.
It is necessary to define, it is a regular DOM node a.
Or if you are with jQuery is easier - then change the code to add event on click as it should be in jQuery.
you just randomly mixed code - of course everything will break. - Janet.Spinka commented on March 20th 20 at 11:59
@lon.Jacobi, no ...right now, I pasted exactly your code and screenshot attached above ... - Bailee83 commented on March 20th 20 at 12:02
in my code the following is the mechanism how to solve the problem with the replacement #. It is designed so that you will think how it works, understand and apply in your code, not just copy-paste and post the error with the words "not working"

I have already written what you need to do to fix it, but I will say more clearly - use .click with jQuery instead of addEventListener. - Janet.Spinka commented on March 20th 20 at 12:05
@lon.Jacobi, as always .... - Bailee83 commented on March 20th 20 at 12:08

Find more questions by tags JavaScript