Reputation: 143
I want to search a certain webpage for a certain string of characters. But I do not want this to be a one of search, I want the program to be constantly searching the webpage for text (the text on the webpage can change). Say maybe do a refresh and search ever minute. But I do not want the webpage to be open when doing this.
When the string of characters has been found a way of informing the user should be there as well. i.e. a text alert box.
Upvotes: 0
Views: 317
Reputation: 14612
Since you want to "track" the changes on the remote page, you have to use the setInterval
function that jQuery offers like below:
var page_contents;
setInterval(function() {
$.ajax({
type: 'GET',
url: '/mypage.html',
success: function (file_html) {
page_contents = file_html;
}
});
}, 1000); // the interval is 1 second, as you specified
Then you can use regular functions to perform the search in the resulted string. You didn't specified exactly what you want to do with the search results, butif you will, and you will need any help about the searching, I will provide an edit of this answer.
You have this JSFiddle that I've just created. But unfortunately, we have to deal with JSONP for external websites. But if the page you want to search in is on your server, then you will have no problem with this code.
For your code to work with extrnal websites, those have to offer a JSONP interface, because otherwise, you will not gain access there (as it is written here):
Many prominent sites provide JSONP services
Upvotes: 1