...

View Full Version : search script not working



jagasker
11-05-2006, 10:52 PM
Hi,

I am trying to write a javascript on Windows XP for my website that is supposed to perform a text search on an external page and return a result which, based on the result, will play a certain audio file. The script that I am writing is not working, I keep on getting redirected to the external page in which I am trying to perform the search, and I am getting numerous javascript errors, such as 'member not found', 'body is null or not an object', 'expected ]', and 'expected ;'. I have been trying to get this script to work all weekend, and it is getting frustrating. Any help to get this script functional would be greatly appriecated. 3 versions of the script are attached below.

jagasker

-------------------------------
Script Version 1
-------------------------------


var adv1=[document="http://www.weather.gov/alerts/pa.html"].body.createTextRange()
var query1a=adv1.findText('Carbon')
var query1b=adv1.findText('Tornado Warning')

if (query1a == true & query1b == true)
document.write('Tornado Warning in effect')
else
document.write('No Alerts')



--------------------------------
Script Version 2
--------------------------------


var adv1=[window.location="http://www.weather.gov/alerts/pa.html"].body.createTextRange()
var query1a=adv1.findText('Carbon')
var query1b=adv1.findText('Tornado Warning')

if (query1a == true & query1b == true)
document.write('Tornado Warning in effect')
else
document.write('No Alerts')



---------------------------------
Script Version 3
---------------------------------


var doc="http://www.weather.gov/alerts/pa.html"
var adv=doc.body.createTextRange()
var query1a=adv1.findText('Carbon')
var query1b=adv1.findText('Tornado Warning')

if (query1a == true & query1b == true)
document.write('Tornado Warning in effect')
else
document.write('No Alerts')

brandonH
11-06-2006, 12:42 AM
let me see if i have this right......

you are trying to grab the content of a webpage belonging to an external site (not yours) and do a search on the content. if you find keywords like tornado watch, you want it to playa sound in your window.

I'm not going to say it cant be done, cuz it acn. may i ask though why you want to do this? are you trying to add it to your own website so hat your users can be informed without having to go to the site you are searching?

jagasker
11-06-2006, 12:52 AM
Yes, you are correct.

jagasker

brandonH
11-06-2006, 01:14 AM
well i have a script that'll do that all written up......
it will work, but the user will be prompted that this page is trying to access something not under its control, blah balh blah, something about a security risk, blah blah blah, and then it asks them if they want to let it happen or not... most users when they see that prompt will click cancel, and your script will not work. I do have to say as well that i do not approve of this sort of thing to be used on a website. if it was for your own personal use to be used on your computer only, then I'd probably not have problem with it.

of course i cant say anything, because i do it myself, lol. so i'm going to post the code up for you.....this time. lol

brandonH
11-06-2006, 01:30 AM
<html>
<head></head>

<body>
<span id=span1></span>
</body>

<script type="text/javascript">
var data='';
function searchPage(url){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){ ;
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request){

if (page_request.readyState == 4 ){
if(page_request.status==200 || window.location.href.indexOf("http")==-1){
data=page_request.responseText;}

// THESE ARE THE VARIABLES YOU SHOULD BE CONSERNED WITH
// BE SURE THAT WHAT YOU SEARCH FOR IS AN EXACT MATCH CAP SENSITIVE
var carbon=data.indexOf('Carbon');
var torwatch=data.indexOf('Tornado Watch');
var noactive=data.indexOf('There are no active watches');


if(noactive!='-1'){
if(carbon!='-1' && torwatch!='-1'){
document.getElementByid('span1').innerHTML="there is a tornado watch in affect in carbon county";}
else{document.getElementById('span1').innerHTML="sorry, no tornado's for carbon county right now";}
}
}
}
searchPage('http://www.weather.gov/alerts/pa.html');
</script>
</html>

jagasker
11-06-2006, 01:38 PM
I have tried the script you gave me in IE, but I get the following javascript error.

Line: 2
Char: 1
Error: Syntax Error
Code: 0

jagasker

jagasker
11-06-2006, 01:45 PM
Disregard my last message - I fixed the syntax error myself



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum