简体   繁体   中英

Excluding a Site Anchor Link javascript

I do have this Code:

<script>
    var link = document.getElementsByTagName("a:not(#)");

    for (var i = 0; i < link.length; i++) {
        link[i].href = link[i].href.replace(/(\?)utm[^&]*(?:&utm[^&]*)*&(?=(?!utm[^\s&=]*=)[^\s&=]+=)|\?utm[^&]*(?:&utm[^&]*)*$|&utm[^&]*/gi, '$1');
    }
    </script>

The Code should lookup for all a tags on the Site and replace all UTMs. Works so far. But there are Anchor Tags on the site wich are now broken.

In the code of the site the Link looks like:

<a href="#newspaper" class="someclass">Newspaper</a>

When I hover over the Link it shows me:

https://www.mysite.or/#newspaper

How do I exclude those Anchor Tags?

此代码返回所有链接,不包括锚点

document.querySelectorAll('a:not([href*="#"])');

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