The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Trying to understand this snippet

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #197865

    Why the elaborate operations at the beginning – is this to prevent code injection to the URL? Wouldn’t using target = $(this).attr('href') instead be a lot more straightforward?

    Let me try and ask the source, @chriscoyier. :-)
    Thanks in advance for a reply by anyone of course.

    Edit – didn’t see the reference page. I’ll read that first…


    A bit more insight, wasn’t the first time I came across that snippet. But now realise it has nothing to do with code injection prevention but filtering out the correct anchors. I was preoccupied with the aforementioned because I just read that getting the window.location.hash and using it in jQuery can easily create a vulnerability.

    Hmm… apparently this.hash is quicker :

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.