3

I'm working with jQuery hashchange event, and every button in my page uses this code like a link to another page:

window.location.hash = '#anotherpage';

When I need to go back to the homepage, location.hash leaves the hash character (#) in my URL, even with location.hash = null or location.hash = ""

Does anyone here know how can I remove the hash in this case?

EDIT:

As Dsafds and Daniel said, only go back to my home page can be easy if I use window.location.hash = "#". The problem is the character (#) in the home page link, used for the other pages, like #contact, is normal, but my home page have the hash too (site.com/#). I need to remove it. Any other idea? Thanks!

3

1 Answer 1

3

You can just use this to go back to the home page:

window.location.hash="/" || window.location.hash="/home"

In your case:

window.location.hash = "#"

EDIT

I made a workaround for the problem you were having.. on removing the hashes.

So what you can do is set the Full Url when you change "locations". For example this:

Lets say you want to go to the login page:

window.location.href = "https://mysite/#/login"

Now you want to go back to the home page! Then you can do this:

window.location.href = "https://mysite/"
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks, Chris! With hash = ' ' I can go back too. The problem is the hash character (#) in the url. My home page link is like mysite.com/#
Yea no problem @ZecaNovaes! Dont forget to mark the question best anwser if it helped you solve the problem to help future users of stackoverflow!
Sure, thank you! I still trying to find any way to remove this hash in my URL, but your answer can help me too!
@ZecaNovaes Edited my anwser to the solution to your problem. Did it help?
Hmm @ZecaNovaes im very sorry i cant solve your problem! I just dont seem to work without refreshes. Ill notify you if i get a solution
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.