2011-01-09 4 views
0

"testing"이라는 단어의 페이지를 확인하고 싶습니다. 또한 URL을 확인하고 싶습니다. 예를 들어, site.com/tester에 있다면 괜찮습니다. 그러나 site.com/testing에 있다면 javascript가 알 수 있습니다. 문서 호스트 이름으로이 작업을 수행 하시겠습니까?키워드 검색 페이지 및 URL

실제 예 : 사용자 이름이 "exgirlfriend"인 페이지를 검색하기 위해 페이지를 검색하고 "exgirlfriend"가 페이지의 아무 곳에서나 발견되는 경우 greasemonkey 스크립트를 만들고 싶습니다. document.body.innerHTML = ''

어떻게하면됩니까?

+1

'var에 전 = document.body.innerHTML.match (/ exgirlfriend /)'? – Anders

답변

3

여기에는 innerHTML과 단어의 URL을 모두 검색하는 항목이 있습니다.

init(); 

function init() 
{ 
    searchWord("exgirlfriend"); 
} 

function searchWord(word) 
{ 
    var pageResults = document.body.innerHTML.match(word); 
    var urlResults = window.location.href.match(word); 
    if(pageResults || urlResults) 
    { 
     alert("word found");  
    } 
} 

http://jsfiddle.net/vfbzc/