简体   繁体   English

HTML Link HREF在检查元素之前不会解析

[英]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. 我想制作一个脚本,以包含在极简主义的Chrome扩展程序模块中。 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. 如果我查询包含许多clickbait链接的页面,则会发现hrefs在检查时发生了变化。 If I query all <a> 's, the links in question will show an href that doesn't include the clickbait domain. 如果查询所有<a> ,则相关链接将显示不包含clickbait域的href。 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. CNN文章和Gizmodo文章具有以这种方式运行的链接。

Based on link provided in comments above, the href's are changed in other event handlers. 根据上面评论中提供的链接,在其他事件处理程序中更改了href。

One example from the cnn page looks a bit like: cnn页面上的一个示例看起来像:

<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 参考MDN Element.attributes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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