-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
  • 29,034
  • 41
  • 131
  • 227

1 Answers1

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

Or even better:

if (window.location.hash.length)
    ...
gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355