fix URL parsing in search-in-context browser trampoline
Use the `URL` class in JavaScript instead of manually parsing a URL string. Related to #1798
This commit is contained in:
parent
bc3e661181
commit
c8ecb5e5fe
|
@ -16,23 +16,20 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
if (location.search.length > 0) {
|
if (location.search.length > 0) {
|
||||||
var paramstrs = location.search.substring(1).split(/[;&]/);
|
var u = new URL(location);
|
||||||
var newsearch = null;
|
var newsearch = "";
|
||||||
for (var i=0; i<paramstrs.length; i++) {
|
for(var key of u.searchParams.keys()) {
|
||||||
var param = paramstrs[i].split(/=/);
|
var val = u.searchParams.get(key);
|
||||||
// an empty "hq=" can be used to clear the cookie
|
// an empty "hq=" can be used to clear the cookie
|
||||||
if (param[0] == "hq") {
|
if (key == "hq") {
|
||||||
SetCookie("PLT_ContextQuery",
|
SetCookie("PLT_ContextQuery", val);
|
||||||
((param.length==2) ? unescape(param[1]) : ""));
|
} else if (key == "label") {
|
||||||
} else if (param[0] == "label") {
|
SetCookie("PLT_ContextQueryLabel", val);
|
||||||
SetCookie("PLT_ContextQueryLabel",
|
|
||||||
((param.length==2) ? unescape(param[1]) : ""));
|
|
||||||
} else {
|
} else {
|
||||||
newsearch = (newsearch == null)
|
if (newsearch == "") newsearch = "?";
|
||||||
? paramstrs[i] : (newsearch + "&" + paramstrs[i]);
|
newsearch = newsearch + "&" + key + "=" + encodeURIComponent(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newsearch = (newsearch == null) ? "" : ("?" + newsearch);
|
|
||||||
// localtion.replace => jump without leaving the current page in the history
|
// localtion.replace => jump without leaving the current page in the history
|
||||||
// (the new url uses "index.html" and the new search part)
|
// (the new url uses "index.html" and the new search part)
|
||||||
location.replace(location.href.replace(/\/[^\/?#]*[?][^#]*/,
|
location.replace(location.href.replace(/\/[^\/?#]*[?][^#]*/,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user