这是我正在尝试做的。我的页面上有一个这样的超链接:
<a href="http://www.wikipedia.com/wiki/Whatever_Page_Here">Whatever Page Here</a>
当用户点击链接时,我想抓取该点击。如果这是一个我不想让他们点击的链接(比如不符合格式 http://www.wikipedia.com/wiki/xxxxx 的东西),我想弹出一个消息框。否则我想通过我的 Mvc Controller 将它们集中起来。像这样:
//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;
}
“返回错误;”告诉 anchor 不要触发导航。
关于javascript - 使用 Javascript/Jquery 重写超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/738145/