我想在查詢字符串中找到一個參數並處理兩件事。 示例URL - http://domainname.com?name=y&track=1&promo=true
jquery查詢字符串匹配和更改選中Href
- 這些附加查詢字符串的頁面上的所有URL的 - 這是好的,我相信。
更改其中包含特定字符串的url的href url本身,然後附加查詢字符串。這些href以不同的方式存在,如href標籤,onclick圖片標籤中。
<a href="http://externaldomain.com/?a=88">link</a>, <img src="a.jpg" onclick = document.location.href="http://externaldomain.com/?a=88" />
到目前爲止的代碼做的第一件事
var querystring = window.location.search.substring(0);
var newurl = "http://changetothisdomain.com/"; //for second criteria
jQuery(document).ready(function() {
jQuery('a[href]').attr('href', function(index, value) {
if ((querystring.indexOf("promo=true") > 0) && (value.indexOf('#') != 0)) {
return value + querystring;
}
});
});
我有這個value.indexOf( '#')!= 0,從而以#的網址是沒有改變,因爲它是爲jQuery選項卡。向這些參數添加參數影響。對於第二件事,我想檢查在查詢字符串中是否有promo = true,然後檢查href是否具有「a = 88」,然後將href更改爲「newurl」並追加查詢字符串。
謝謝!
我是我的手機上,並試圖給你一個腳本是比較通用的,所以你可以,如果做'(getParm (「promo」)==「true」&& getParm(「a」)==「88」)'既然你沒有使用這樣的腳本,我以爲你沒有發現它 – mplungjan
好的謝謝。它只是沒有清楚的搜索鏈接,所以我這樣回答。將研究getparam方法。再次感謝 – Jay