Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've been using a script which prefixes redirect.php on "onmouseevent" triggers. But I don't want it on certain sites, like google etc. Please see the code below:

var matchavailable = 0;
var disallowinks = "google,microsoft,yahoo";
$n("a").mousedown(function () {
    var linkArray = disallowlinks.split(',');
    for (var i = 0; i < linkArray.length; i++) {
        if ($n(this).attr('href').indexOf(linkArray[i]) > 0) {
            matchavailable = 1;
            break;
        }
        else {
            matchavailable = 0;
        }
    }

    if (matchavailable == 0) {
        if ($n(this).hasClass('linked')) {
        }
        else
        {
           $n(this).attr('href', "http://yoursite.com/redirect.php?q=" + encodeURIComponent($n(this).attr('href')));
           $n(this).attr('target', '_blank');
           $n(this).addClass("linked");
        }


    }

});

The javascript runs so far so good on all anchor tags. Just that, I have a popup which I show on my website and when I try to close the popup (X marks the spot), the redirect.php gets prefixed on that as well.

So my question is, how do we disallow the script to NOT run on anchor tags with the value starting with "javascript" ?

For example, i don't want it to run on:

<a href="javascript:void"> or <a href="any random parameter">

How do I go about this? WOuld be great to get some help

share|improve this question
    
var disallowinks = "google,microsoft,yahoo,javascript:"; ? –  pawel Sep 21 '13 at 20:49
    
@Jeffman did you read the question, or just the title? BTW adding javascript: to the list of excluded strings (as I've suggested above) is just as bad as your starting point, i.e. not checking the location of the string in the url. http://mysite.com/i_like_google.php will not be passed to the redirect.php, because index of google in this url is >0. –  pawel Sep 21 '13 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.