2015-10-17 40 views
0

我在制作小书签,它检查主体是否存在特定的文本字符串,并在找到时运行脚本。我用document.body.search();但它只是给出了控制台错误消息使用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; 
} 
+0

显然'document.body.search'不存在。你期望它做什么? – melpomene

+0

我不认为'document.body'有搜索功能。要检查文本片段,您可能需要迭代所有搜索的元素,并将它们与文本字符串进行比较。 – Ryan

回答

0

的检查应该是:

document.body.textContent.indexOf('application is temporarily over its serving quota') > -1 

没有document.body.search但location.search(),它不是关于搜索文本。你误解了文档。