Today I'm interested to try the following interesting piece of Javascript in Chrome:-
Array.from(document.getElementsByClassName('r')).forEach(x => console.log(x.firstChild.href))
As expected, this list out all the target url (without Google tracking) in my console. However when I try to inspect the href
of the anchor
, it turns out that the href
is actually the Google tracking url and the target url (without Google tracking) is in the data-href
instead.
I expect the value of href
should be the target url (without Google tracking). May I know what's the cause of this discrepancy?
In fact, I noticed that the anchor inside the Google Search Result Page will trigger an event on mouse click which will change the orignal value of href
and embed it in data-href
instead.
That means as long as the anchor doesn't get clicked, the original url of the value of the href
will be preserved.
My current knowledge doesn't allow me to drill down further and any more detailed or technical explanations are welcome! =)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments