Reputation: 469
I am a newbie to javascript and trying to search for text in an external html page. I am trying to achieve this directly on the browser and hence nodejs is not an option.
I know this is not the very kind of question asked on SE but I am left with no option. So far even an extensive search on internet didn't solve my problem. Any pointer could be helpful.
Upvotes: 0
Views: 160
Reputation: 36703
Yes it can be done, you should be using PHP Simple HTML DOM Parser
Include this http://simplehtmldom.sourceforge.net/
PHP
//find.php
<?php
$url = $_REQUEST['url'];
$strtofind = $_REQUEST['strtofind'];
$cont = file_get_html($url)->plaintext;
$pos = strpos($cont , $strtofind );
echo ($pos==false?"Not found":"Found");
?>
Here is JS Function
//js function
$.get("find.php?url="+url+"&strtofind="+strtofind, function(data){
console.log(data);
});
Pass whatever URL you want to paas. The JS will make a request and the PHP file will give the source code.
Upvotes: 0
Reputation: 2332
I don't think there is an easy way to do it in client, it's typical job on server side. Browser will block such script for security reason.
Upvotes: 1