我的应用程序适用于以下代码。即,点击一次按钮即可打开google.com。
function scan(arr, w) {
// This function is a first attempt to solve your specific problem.
// It just looks for the first occurence of w, the word you are looking for
// It does not cover edge or specific cases, neither is optimized.
// With more specifications, it can be generalized.
// Hope it can help.
var
// utils
regWord = /\w+/g,
wordsBefore, wordsAfter,
matchWord,
found = false;
// loop through your array
arr.forEach(function(item) {
if (found) {
// if we have already found the word, skip the iteration
return false;
}
// clear the arrays of words before and after
wordsBefore = [];
wordsAfter = [];
// strip the words from the array item
// every match is an iterable object containing the word, its index, and the item string
while (match = regWord.exec(item)) {
// get the matched word
matchWord = match[0].toLowerCase();
// if we have found the word we are looking for
if (matchWord === w.toLowerCase()) {
// flag it
found = true;
} else {
// it is not a match, but a word that could be returned in the array before or after
if (!found) {
// if we have not found the word yet
// populate the array of words before
wordsBefore.push(matchWord);
} else {
// otherwise, if we are here, it means that we are in a sentence containing
// the word we are looking for, and we have already found it
// populate the array of words after
wordsAfter.push(matchWord);
}
}
}
});
// return an object containing
return {
// the words before
wordsBefore: wordsBefore,
// the words after
wordsAfter: wordsAfter
}
}
现在,假设某人正在使用我的应用程序,几天后我想将网址从google.com更改为yahoo.com,我应该遵循什么方法。我对它完全无能为力。我是否应该获得域名并将其重定向更改为abc.com/test.html以重定向到google.com,然后将更改方向更改为yahoo.com或其他方法?
答案 0 :(得分:0)
我可以给你两个想法:
在您的代码中保留一系列网址,然后随机选择一个以使用。
如果你维护一个服务器,那么你可以使用一个静态网址,你的程序将从那里接收只有url或url列表的数据并使用它。