-5

Similar to SO, I want to have an anchor for some comment and after the page is loaded I want the page to do some javascript (highlight,scrolling, etc - that I can write myself)

So If my url is

www.mywebapp.com/mypost#45625

I'd like the javascript to scroll to div with id 45625 and do my own javascript there.

How can I write the condition for which to start the execution of my javascript so it would work only if an achor exists?

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244

1 Answers1

6
if (window.location.href.indexOf('#') > -1)
    // Do something.

Or even better:

if (window.location.hash.length)
    ...
gdoron
  • 147,333
  • 58
  • 291
  • 367