jQuery:拦截去向链接并添加参数 [英] jQuery: intercepting out going link and adding parameters
本文介绍了jQuery:拦截去向链接并添加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户单击我页面上的链接时,我需要在浏览器对其进行操作之前,将参数Hello = True添加到网址中.
When a user clicks a link on my page, I need to, before it gets actioned by the browser, add the param Hello=True to the url.
因此,用户在其中单击MyPage.aspx,然后将其发送到MyPage.ASPX?Hello = True.
So, the user clicks MyPage.aspx in and gets sent to MyPage.ASPX?Hello=True instead.
必须是客户端,最好使用jQuery
Has to be client side, preferably using jQuery
如果需要,我可以向标签添加属性.
I can add an attribute to the tags if needed.
伊恩
推荐答案
如果您需要操纵所有链接,请使用以下方法:
if you need all links to be manipulated, use this:
$('a').each(function() {
var href = this.href;
if (href.indexOf('?') != -1) {
href = href + '&Hello=True';
}
else {
href = href + '?Hello=True';
}
$(this).attr('href', href);
});
这篇关于jQuery:拦截去向链接并添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文