2009-04-10 50 views
1

这里重写就是我“米试图做我有这样一个超级链接我的网页上:。超链接使用Javascript/jQuery的

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

当用户点击我要抢点击链接如果是一个链接,我不希望他们点击(喜欢的事,不符合格式http://www.wikipedia.com/wiki/xxxxx)我想弹出一个消息框,否则,我想通过我的mvc控制器漏斗他们,而不是像这样:。

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

} 

有什么建议吗?

+0

我还没有看到有人使用“超级链接”在这么长... – 2009-04-10 16:36:44

+0

我使用它,因为它是复古的。非常怀旧。我也喜欢像万维网这样的其他内容。 – Micah 2009-04-10 16:40:16

回答

3

开始通过拦截所有单击事件:

$(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; 
} 

的“返回false;”告诉锚点不火的导航。