簡體   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