Mrk*_*abs 1 javascript google-chrome-extension
我想从 URL 中提取 TLD,但它给了我整个 URL。例如https://www.google.com.uk -> .com.uk。
$(document).on("click", "a", function() {
var href = $(this).attr("href");
alert(href)// It gives me the whole link of website
if(href.search(".com.uk")){
alert("This website is AUTHENTIC!");
}
else
{
alert("Not AUTHENTIC!")
}
Run Code Online (Sandbox Code Playgroud)
要获取域的最后一部分,例如comin example.com,请使用以下内容:
const tld = window.location.origin.split('.').pop();
Run Code Online (Sandbox Code Playgroud)
但是,eTLD 之类的co.uk需要特殊情况。如果你想硬编码一个检查.co.uk:
const isUK = window.location.origin.endsWith('.co.uk');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4016 次 |
| 最近记录: |