Redirect links on a webpage to a javascript function
<p>I am trying to redirect links on a web page and in this simple example, it just goes through a simple check for a cookie to be set.</p>

<p>Not sure if that's the right way to take care of this situation in the first place, and if I am going to run into problem when there are several links with the "download_link" class, but even right now, with only one of such link, the destination is set to undefined, it looks like the $(this) in the call to redirector is actually pointing the the whole HTML document instead of just the element I am trying to change...</p>

<pre><code>    function redirect_link(e, destination) {
        if ($.cookie("contact_set") == "true") {
            window.location.href = destination;
        } else {
            alert("cookie not set");
        }
    }
    function redirector(destination) {
        alert("creating redirector to "+destination);
        return function(e) {redirect_link(e, destination)};
    }
    $(document).ready(function() {
        $('.download_link').click(redirector($(this).attr("href")));
        $('.download_link').attr("href", "#");
    });
</code></pre>
