有一个外部函数GoSearch,存在于javascript文件search.js
中如何覆盖GoSearch函数的私有/局部变量(b)。 示例修改变量b =“?”到b =“?cs =本网站& u = http://google.com”
GoSearch(q, G, p, E, r, F, D, C, B, j, n, z, y, x, w, A, l, v) {
ULShpi: ;
try {
AddSearchoptionsToQuery()
} catch (H) {}
var i = document.forms[0].elements[G].value;
i = i.replace(/\s*$/, "");
var u = "1";
if (q) u = document.forms[0].elements[q].Value;
if (i == "" || u == "0") {
alert(v);
if (null != event) {
event.returnValue = false;
return false
} else return
}
var b = "?";
if (suggestedQuery) b += "sq=1&";
b += "k=" + encodeURIComponent(i);
for (var k = ["rm", "rm1", "rm2", "rm3", "rm4", "rm5", "ql", "ql1", "ql2", "ql3", "ql4", "ql5", "v", "v1", "v2", "v3", "v4", "v5", "hs", "hs1", "hs2", "hs3", "hs4", "hs5"], h = 0; h < k.length; h++) {
var m = GetUrlKeyValue(k[h], true);
if (m && m.length > 0) b += "&" + k[h] + "=" + m
}
if (l != null && l != "") b += "&r=" + encodeURIComponent(l);
if (null != p) {
var t = document.forms[0].elements[p].value;
if (E) b += canonicalizedUtf8FromUnicode(" " + t);
else b += "&a=" + canonicalizedUtf8FromUnicode(" " + t)
}
var a = null,
c = "",
d = "",
o = null != j;
if (o) {
c = j;
d = j
} else if (r) {
a = document.forms[0].elements[F];
c = a.options[a.selectedIndex].getAttribute("scope");
d = a.options[a.selectedIndex].value
}
if (r || o) {
var f = "",
g = "",
e = false;
if (d == z) {
f = d;
c = "";
g = document.forms[0].elements[D].value;
e = true
}
if (d == y) {
f = d;
c = "";
g = document.forms[0].elements[C].value;
e = true
}
if (d == x) {
f = c;
c = "";
g = document.forms[0].elements[B].value;
e = true
}
if (c == w) {
c = a.options[a.selectedIndex].value;
e = true
}
if (e) n = A;
if (c != "") {
b += "&s=" + encodeURIComponent(c);
if (a.options[a.selectedIndex].value != "" && !e) n = a.options[a.selectedIndex].value
}
if (f != "") b += "&cs=" + encodeURIComponent(f);
if (g != "") b += "&u=" + encodeURIComponent(g)
}
var I = document.forms[0];
try {
external.AutoCompleteSaveForm(I)
} catch (s) {}
window.location = n + b;
try {
if (null != event) event.returnValue = false
} catch (s) {}
return
}
答案 0 :(得分:1)
您可以使用搜索框将GoSearch
功能替换为您自己的GoSearch
功能 - delegate control。
创建一个用户控件(ASCX),它将JavaScript代码放在具有修改后的AdditionalPageHead
函数的页面上。创建一个SP解决方案,其功能将控件置于search.js
- 您激活该功能的网站或网站集上的每个页面头。
查看您的网页上GoSearch
的加载方式。如果不是直接在页眉中完成但是延迟,则必须在加载search.js
后动态执行function ReplaceGoSearch {
GoSearch = function(...) {
...
};
}
ExecuteOrDelayUntilScriptLoaded(ReplaceGoSearch, "search.js");
替换:
{{1}}
---费达
答案 1 :(得分:0)
您可以执行此操作的最快方法是不直接链接到外部文件。下载您的文件版本,更改您需要的内容,然后将其提供给您的页面。
您甚至可以将文件即时下载到您的服务器,进行修改,然后将其推送到请求页面。