By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

Search for or find a word within the page using javascript

P: 5
There is two frame in my form.In d first frame there is a text box,and i give some word in the text box.I want to search the word from a file from the location(http://45.12.09.31...........) and if the word is found any file of that location,
the file will display in second frame.
main problem is arise in the following line.
txt = s.document.body.createTextRange();


here the code is :
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta http-equiv="Content-Language" content="en-us">
  5. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  6. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  7. <meta name="ProgId" content="FrontPage.Editor.Document">
  8. <title>New Page 1</title>
  9. </head>
  10.  
  11. <body>
  12.  
  13. <p align="center">&nbsp;</p>
  14.  
  15. <p align="center">&nbsp;</p>
  16.  
  17. <p align="center"><b><u><span style="background-color: #FFFFFF"><font face="Copperplate Gothic Bold" size="6" color="#000080">Find
  18. The Page</font></span></u></b></p>
  19. <p align="center">&nbsp;</p>
  20. <p align="center">&nbsp;</p>
  21. <p align="center">&nbsp;</p>
  22.  
  23.   <p align="center">
  24. &nbsp;
  25.   </p>
  26.  
  27. <Script language = JavaScript>
  28. var year = new Array("2007");//,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018
  29. var month  = new Array("May");//,"Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  30.  
  31.  
  32. var i = 0;
  33. var i1 = 0;
  34. var IE4 = (document.all);
  35. var n   = 0;
  36.  
  37. function findInPage1(str) 
  38. {
  39.   var  i2,txt,found;
  40.  
  41. for(i=0;i<year.length;i++)
  42.  {
  43.   for(i1=0;i1<month.length;i1++)
  44.   {
  45.    s="http://10.50.110.59:1977/archive/sysdoc1_";
  46.     s+=month[i1];
  47.     s+=year[i];
  48.     s+=".htm";
  49.     //parent.word_f2.location.href=s;
  50.  
  51.  
  52.     if (str == "")
  53.     return false;
  54.  
  55.      if (IE4)
  56.       {
  57.     //txt = window.document.body.createTextRange();
  58.     //txt = parent.word_f2.document.body.createTextRange();
  59.    txt = s.document.body.createTextRange();
  60.  
  61.  
  62.     // Find the nth match from the top of the page.
  63.  
  64.     for (i2 = 0; i2 <= n && (found = txt.findText(str)) != false; i2++) {
  65.       txt.moveStart("character", 1);
  66.       txt.moveEnd("textedit");
  67.      }
  68.  
  69.      if (found) {
  70.     // document.write(s);
  71.      parent.word_f2.location.href=s;
  72.        txt.moveStart("character", -1);
  73.        txt.findText(str);
  74.        txt.select();
  75.        txt.scrollIntoView();
  76.       n++;
  77.     }
  78.  
  79.     else {
  80.       if (n > 0) 
  81.       {
  82.        //document.write(qqq);
  83.  
  84.         n = 0;
  85.         findInPage1(str);
  86.       }
  87.  
  88.       // Not found anywhere, give message.
  89.  
  90.       else
  91.       //{
  92.       //document.write(wewe);
  93.  
  94.         alert("Not found.");
  95.        // }
  96.     }
  97.     }
  98.       return false;
  99.  
  100.  
  101.   }//for loop1
  102.  }//for loop2
  103. }
  104.  
  105.  
  106. </script>
  107.  
  108. <form name="search" onSubmit="return findInPage1(this.string.value);">
  109. <p align="center">
  110. <font size=3 face="t"><b><input name="string" size=15 onChange="n =  0;"></b></font>
  111.  <span style="background-color: #00FFFF">
  112. <input type="submit" value="Search" style="font-size: 12pt; font-family: Times New Roman; font-weight: bold; color: #0000FF"></span></form>
  113.  
  114.  
  115. </body>
  116.  
  117. </html>
  118.  

Plz help.thanking you.
Dec 28 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Check out this link and see if it helps solve your problem.

PS. I've changed the thread title.
Dec 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.