简体   繁体   中英

Html Link HREF doesn't resolve until element is inspected

I'd like to make a script to include in a Minimalist Chrome Extension module. The first cut will, on load, find all links on a page, find which links include a blacklisted website name, and then remove itself.

If I query a page that contains a number of clickbait links, I find that the hrefs change upon inspection. If I query all <a> 's, the links in question will show an href that doesn't include the clickbait domain. If I right-click and inspect, then query again, all of the sudden they are there.

What the heck is going on and how can I catch it? CNN articles and Gizmodo articles have links that behave in this way.

Based on link provided in comments above, the href's are changed in other event handlers.

One example from the cnn page looks a bit like:

<a onmousedown="this.href='http://paid.outbrain.com/network/redir?p=Mq...."

You could try parsing the element attributes to look for the blacklisted domains.

Reference MDN Element.attributes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM