1

Here's what I"m trying to do. I have a hyperlink like this on my page:

<a href="http://www.wikipedia.com/wiki/Whatever_Page_Here">Whatever Page Here</a>

When a user clicks the link I want to grab that click. If it's a link I don't want them to click (like something that doesn't match the format http://www.wikipedia.com/wiki/xxxxx) I want to pop a message box. Otherwise I want to funnel them through my Mvc Controller instead. like this:

//Category is the "Whatever_Page_Here" portion of the Url that was clicked.
public ActionResult ContinuePuzzle(string category)
{

}

Any suggestions?

2
  • I haven't seen someone use the term "hyperlink" in so long... Commented Apr 10, 2009 at 16:36
  • I use it cuz it's retro. Very nostalgic. I also like to refer to other things too like the world wide web. Commented Apr 10, 2009 at 16:40

2 Answers 2

3

Start by intercepting all the click events:

$(function() {
    $("a").click(ClickInterceptor);
});

function ClickInterceptor(e)
{
    // code to display popup or direct to a different page
    if (redirect)
    {
        var href = $(this).attr("href").split("/");
        location.href = "http://mydomain.com/controller/" + href[href.length - 1];
    }

    return false;
}

The "return false;" tells the anchor not to fire the navigate.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! That's exactly what I need. How can redirect them though?
1

If you want to select all the a tags which do not start with "http://http://www.wikipedia.com/wiki/" you would use:

$("a").not("a[href^='http://http://www.wikipedia.com/wiki/']")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.