Javascript detect # in url

My application is an iframe application, so when the user changes the page, they do not automatically get to the top. To deal with this when loading a page, I call

window.location.hash = 'tophash' 

However, I found that in some rare cases I need to take the user to a specific part of the page. Therefore, I am doing the C # urlID url at the end. Currently, the problem is that they are loading on the page.

I need if there is a hash in the url it doesn't start window.location.hash = 'tophash'

So my question is ... how do I determine if # is in the URL?

+6
javascript
source share
1 answer

The request for the hash property must complete the task before tuning.

 if ((!window.location.hash) || (window.location.hash == "#")) window.location.hash = "tophash"; 
+3
source share

All Articles