开发者

Search page and URL for keyword

I would like to check the page for the word "testing", also I would like to check the URL. So for example if you're on site.com/tester that's fine, but if you're on site.com/testing javascript would know. Would you do this with document hostname?

Real world example: Pretty much I just want to cr开发者_Go百科eate a greasemonkey script to search a page to search a page/url for a username "exgirlfriend" and if "exgirlfriend" is found anywhere on the page document.body.innerHTML= ''

How would I do this?


Here's something that searches both the innerHTML and the URL for your word.

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜