【发布时间】:2015-10-17 14:21:05
【问题描述】:
我正在制作一个 bookmarklet,它会检查正文中的特定文本字符串并在找到时运行脚本。我正在使用document.body.search();,但它只是给出了错误消息
[Error] TypeError: undefined is not a function (evaluating 'document.body.search('application is temporarily over its serving quota')')
在控制台中。我使用search() 错了吗?我应该使用document.body以外的东西吗?
Javascript
var prox='http://proxy-mirror.appspot.com/';
var prox1='http://toproxies.appspot.com/';
var prox2='http://meprxy.appspot.com/';
var prox3='http://i-love-proxy.appspot.com/';
var prox4='http://proxy0server.appspot.com/';
var prox5='http://proxy1server.appspot.com/';
var x=document.body.search('application is temporarily over its serving quota');
var url=window.location.href;
if(x!==-1) {
switch(window.location.hostname) {
case 'proxy-mirror.appspot.com':url.slice(32);window.location.href=prox1+url;
break;
case 'toproxies.appspot.com':url.slice(29);window.location.href=prox2+url;
break;
case 'meprxy.appspot.com':url.slice(26);window.location.href=prox3+url;
break;
case 'i-love-proxy.appspot.com':url.slice(32);window.location.href=prox4+url;
break;
case 'proxy0server.appspot.com':url.slice(32);window.location.href=prox5+url;
break;
case 'proxy1server.appspot.com':alert('Whoops!\n\nIt seems this site is over its quota, and its the last proxy I have on the list\n\nSorry about that, please wait until tomorrow when the servers reset and you\'ll be good to go!');break;
}
} else {
window.location.href=prox+url;
}
【问题讨论】:
-
显然
document.body.search不存在。你期望它做什么? -
我觉得
document.body没有搜索功能。要检查文本的 sn-ps,您可能必须迭代您正在搜索的所有元素并将它们与您的文本字符串进行比较。
标签: javascript search document bookmarklet