Search phrases on page

Discussion in 'JavaScript' started by blue_angel, May 9, 2009.

  1. #1
    I have a page and I want to search for some words.
    and display relevant messages

    I used the following for the title
    Example1
    var sentence=document.title;
    if (sentence.indexOf("Hello")!=-1)
    document.writeln ("Hello world");

    and I am looking for the body

    I tried to use
    <script type="text/javascript">
    var str=document.body;
    document.write(str.search(/w3schools/i));

    </script>



    even and paid help please :confused:
     
    blue_angel, May 9, 2009 IP
  2. JavaScriptBank.com

    JavaScriptBank.com Peon

    Messages:
    141
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    JavaScriptBank.com, May 9, 2009 IP
  3. hiteklife

    hiteklife Greenhorn

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Hi blue_angel! I think I know what you're after.

    Try replacing:
    With:
    and see if that works. innerHTML is a really handy piece of code. Works on div/span/p... pretty much anything you can think of actually! Let me know if this helps :)
     
    hiteklife, May 10, 2009 IP
  4. blue_angel

    blue_angel Well-Known Member

    Messages:
    1,174
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Thanks all for their reply you helped me a alot
    THANK YOU ALL
     
    blue_angel, May 10, 2009 IP
  5. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #5
    just make sure your js code is outside of the body tag else it will find itself :)
     
    dimitar christoff, May 11, 2009 IP