The following script adds my affiliate extension to every url on my page. For example, if is on my page somewhere... Adding this script to the page will automatically change the url to- - this goes for every url on the page...

This script works great if the urls on the page are already hyperlinked, because the link text stays the same, but the destination url now has my affiliate extension on it.

My question is... How could I modify this script to make it so that raw urls (not hyperlinked) can still be shown as the original url, but with my affiliate extension added to the destination? Better put, I need this script to hyperlink all of the raw urls on the page. I need it so that if I have the raw url on my page, the script will change the destination to- - but the viewer will still only see

Again, this script works fine with hyperlinks already as it only affects the URLs, not the link text. I just need it to cloak/mask/hyperlink all of the raw urls, so that viewers still see the original URL destination, rather than the new one with my affiliate extension on it.

Thank you in advance, Here is the example HTML code:

<script type="text/javascript">
    onmousemove = function adfly() {
        adfly_id = 'xxxxxx';
        for(var i = 0; i < document.links.length; i++) {
            var hrefer = document.links[i].href;
            if(hrefer.match("") || hrefer.match("javascript:") || hrefer.match("#")) {
                document.links[i].href = document.links[i].href;
            } else {
                document.links[i].href = '' + adfly_id + '/' + document.links[i].href;

What do you mean with raw url, an url without a hyperlink ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.