如何获得“原始” JavaScript中的href内容 [英] How to get "raw" href contents in JavaScript
本文介绍了如何获得“原始” JavaScript中的href内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个GreaseMonkey脚本,我希望在其中找到所有相关链接的链接。在我看来,这样做的方法是将href的内容与 / ^ https?:///
相匹配。
I am trying to write a GreaseMonkey script in which I want to find all of the links that are relative links. It seemed to me that the way to do that would be to match the contents of href against /^https?:///
.
但是我发现当我访问锚点的href属性时,它总是被标准化或者变成一个包含http的表单。也就是说,如果HTML包含:
But I find that when I access the anchor's href attribute, it's always normalized or cooked into a form that contains "http". That is, if the HTML contains:
<a id="rel" href="/relative/link">inner</a>
访问
document.getElementById("rel").href
返回
http://example.com/relative/link
如何访问href属性中的原始数据?
How can I access the raw data in the href attribute?
或者,有没有更好的方法来查找相对链接?
Alternately, is there a better way to find relative links?
推荐答案
尝试 getAttribute
方法。
这篇关于如何获得“原始” JavaScript中的href内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文