Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:35:17+00:00 2026-06-10T08:35:17+00:00

I am trying to redirect links on a web page and in this simple

  • 0

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.

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…

    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", "#");
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:35:19+00:00Added an answer on June 10, 2026 at 8:35 am

    You’re accessing $(this) from the scope of document’s ready callback, so $this points to a HTMLDocument object!

    $(document).ready(function() {
        var $downloadLnk = $('.download_link');
        $downloadLnk.click(redirector($downloadLnk.attr("href")));
        $downloadLnk.attr("href", "#");
    });
    

    As you requested it in your comment:

    $(document).ready(function() {
      $('.download_link').each(function() {
        var $lnk = $(this);
        $lnk.click(redirector($lnk.attr("href")));
        $lnk.attr("href", "#");
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to redirect this page Page to a Jquery mobile website that I'm
I'm trying to redirect all links to a particular page on our site to
Im trying to redirect pages such as: /selected-work/project-name-1 /selected-work/project-name-2 /selected-work/project-name-3 /selected-work/category/category-name to just /work/
I'm trying to redirect to a .php page if the $validForm variable is TRUE.
I am trying to create an simple link hider to hide external links. I
Hi I am trying to redirect all links to any pdf file in my
What I'm trying to do is this: I've got a web app the user
I've seen several questions regarding similar requests, however, I'm not trying to redirect to
I've been trying to redirect my subdomain buynow.mydomain.info to the product link which is
I'm trying to redirect a few pages to a new domain and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.