繁体   English   中英

使用Javascript / Jquery进行超链接重写

[英]Hyperlink Rewriting with 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)
{

}

有什么建议么?

首先拦截所有点击事件:

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

“回归虚假”; 告诉船锚不要开火导航。

如果您想选择所有不以“ http:// http://www.wikipedia.com/wiki/ ”开头的标签,您可以使用:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM