您還可以使用正則表達式: 「?」
var regex = /.+(\?h=|&h=)([^&]+).+/g;
var url = 'https://m.facebook.com/logout.php?h=BfcGpI0GW8PKKFtX&t=1494184226&button_name=logout&button_location=settings';
var m, newUrl;
while ((m = regex.exec(url)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
++regex.lastIndex;
}
newUrl = url.replace(m[2], 'REPLACEMENT');
// m[2] because the first match is the whole url and
// the second one is "?h=" (or "&h=").
// the third one (index 2) is the one you want to replace.
document.getElementById("output").innerHTML = newUrl;
}
<span id="output"></span>
唯一的一點是,在 「H」 參數需要是第一位的,在後。
編輯:我調整了正則表達式,以便「h」參數可以在url中的任何地方。
'BfcGpI0GW8PKKFtX'是否總是h的值,並且這是在Java還是Javascript中,您已經標記了Android和Javascript? –
是你在尋找android原生或JavaScript更改標籤根據 – Pavan