Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    search script not working

    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
    -------------------------------
    Code:
    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
    --------------------------------
    Code:
    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
    ---------------------------------
    Code:
    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')

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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?
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, you are correct.

    jagasker

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Code:
    <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>
    Last edited by brandonH; 11-06-2006 at 01:33 AM.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #6
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Disregard my last message - I fixed the syntax error myself


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •