The following script adds my affiliate extension to every url on my page. For example, if http://www.Google.com/ is on my page somewhere... Adding this script to the page will automatically change the url to- http://adf.ly/xxxxxx/http://www.Google.com/ - 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 http://www.Google.com on my page, the script will change the destination to- http://adf.ly/xxxxxx/http://www.Google.com/ - but the viewer will still only see http://www.Google.com.

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("adf.ly") || hrefer.match("javascript:") || hrefer.match("#")) {
                document.links[i].href = document.links[i].href;
            } else {
                document.links[i].href = 'http://adf.ly/' + adfly_id + '/' + document.links[i].href;
            }
        }
    }
</script>

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, networking, learning, and sharing knowledge.