473,774 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

find in page script

5 New Member
Is any ColdFusion script I can put on my webpage that will create a search bar so people can type keywords to match it on the current page in my website? It will be exactly like the finder search bar that comes with your browser window, IE; click edit, then find on this page, which brings up the search box.

I know that JavaScript can do this. I tried to insert JavaScript to my .cfm page. It doesn't work. Any help will be appreciated.

Here is the JavaScript and Form code I used:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. <!-- Hide from old browsers
  3.  
  4. /******************************************
  5. * Find In Page Script -- Submitted/revised by Alan Koontz (alankoontz@REMOVETHISyahoo.com)
  6. * Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code
  7. * This notice must stay intact for use
  8. ******************************************/
  9.  
  10. //  revised by Alan Koontz -- May 2003
  11.  
  12. var TRange = null;
  13. var dupeRange = null;
  14. var TestRange = null;
  15. var win = null;
  16.  
  17.  
  18. //  SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT
  19. //  http://www.mozilla.org/docs/web-deve...wser_type.html
  20.  
  21. var nom = navigator.appName.toLowerCase();
  22. var agt = navigator.userAgent.toLowerCase();
  23. var is_major   = parseInt(navigator.appVersion);
  24. var is_minor   = parseFloat(navigator.appVersion);
  25. var is_ie      = (agt.indexOf("msie") != -1);
  26. var is_ie4up   = (is_ie && (is_major >= 4));
  27. var is_not_moz = (agt.indexOf('netscape')!=-1)
  28. var is_nav     = (nom.indexOf('netscape')!=-1);
  29. var is_nav4    = (is_nav && (is_major == 4));
  30. var is_mac     = (agt.indexOf("mac")!=-1);
  31. var is_gecko   = (agt.indexOf('gecko') != -1);
  32. var is_opera   = (agt.indexOf("opera") != -1);
  33.  
  34.  
  35. //  GECKO REVISION
  36.  
  37. var is_rev=0
  38. if (is_gecko) {
  39. temp = agt.split("rv:")
  40. is_rev = parseFloat(temp[1])
  41. }
  42.  
  43.  
  44. //  USE THE FOLLOWING VARIABLE TO CONFIGURE FRAMES TO SEARCH
  45. //  (SELF OR CHILD FRAME)
  46.  
  47. //  If you want to search another frame, change from "self" to
  48. //  the name of the target frame:
  49. //  e.g., var frametosearch = 'main'
  50.  
  51. //var frametosearch = 'main';
  52. var frametosearch = self;
  53.  
  54.  
  55. function search(whichform, whichframe) {
  56.  
  57. //  TEST FOR IE5 FOR MAC (NO DOCUMENTATION)
  58.  
  59. if (is_ie4up && is_mac) return;
  60.  
  61. //  TEST FOR NAV 6 (NO DOCUMENTATION)
  62.  
  63. if (is_gecko && (is_rev <1)) return;
  64.  
  65. //  TEST FOR Opera (NO DOCUMENTATION)
  66.  
  67. if (is_opera) return;
  68.  
  69. //  INITIALIZATIONS FOR FIND-IN-PAGE SEARCHES
  70.  
  71. if(whichform.findthis.value!=null && whichform.findthis.value!='') {
  72.  
  73.        str = whichform.findthis.value;
  74.        win = whichframe;
  75.        var frameval=false;
  76.        if(win!=self)
  77. {
  78.  
  79.        frameval=true;  // this will enable Nav7 to search child frame
  80.        win = parent.frames[whichframe];
  81.  
  82. }
  83.  
  84.  
  85. }
  86.  
  87. else return;  //  i.e., no search string was entered
  88.  
  89. var strFound;
  90.  
  91. //  NAVIGATOR 4 SPECIFIC CODE
  92.  
  93. if(is_nav4 && (is_minor < 5)) {
  94.  
  95.   strFound=win.find(str); // case insensitive, forward search by default
  96.  
  97. //  There are 3 arguments available:
  98. //  searchString: type string and it's the item to be searched
  99. //  caseSensitive: boolean -- is search case sensitive?
  100. //  backwards: boolean --should we also search backwards?
  101. //  strFound=win.find(str, false, false) is the explicit
  102. //  version of the above
  103. //  The Mac version of Nav4 has wrapAround, but
  104. //  cannot be specified in JS
  105.  
  106.  
  107.         }
  108.  
  109. //  NAVIGATOR 7 and Mozilla rev 1+ SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6)
  110.  
  111. if (is_gecko && (is_rev >= 1)) {
  112.  
  113.     if(frameval!=false) win.focus(); // force search in specified child frame
  114.     strFound=win.find(str, false, false, true, false, frameval, false);
  115.  
  116. //  The following statement enables reversion of focus 
  117. //  back to the search box after each search event 
  118. //  allowing the user to press the ENTER key instead
  119. //  of clicking the search button to continue search.
  120. //  Note: tends to be buggy in Mozilla as of 1.3.1
  121. //  (see www.mozilla.org) so is excluded from users 
  122. //  of that browser.
  123.  
  124.     if (is_not_moz)  whichform.findthis.focus();
  125.  
  126. //  There are 7 arguments available:
  127. //  searchString: type string and it's the item to be searched
  128. //  caseSensitive: boolean -- is search case sensitive?
  129. //  backwards: boolean --should we also search backwards?
  130. //  wrapAround: boolean -- should we wrap the search?
  131. //  wholeWord: boolean: should we search only for whole words
  132. //  searchInFrames: boolean -- should we search in frames?
  133. //  showDialog: boolean -- should we show the Find Dialog?
  134.  
  135.  
  136. }
  137.  
  138.  if (is_ie4up) {
  139.  
  140.   // EXPLORER-SPECIFIC CODE revised 5/21/03
  141.  
  142.   if (TRange!=null) {
  143.  
  144.    TestRange=win.document.body.createTextRange();
  145.  
  146.  
  147.  
  148.    if (dupeRange.inRange(TestRange)) {
  149.  
  150.    TRange.collapse(false);
  151.    strFound=TRange.findText(str);
  152.     if (strFound) {
  153.         //the following line added by Mike and Susan Keenan, 7 June 2003
  154.         win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
  155.         TRange.select();
  156.         }
  157.  
  158.  
  159.    }
  160.  
  161.    else {
  162.  
  163.      TRange=win.document.body.createTextRange();
  164.      TRange.collapse(false);
  165.      strFound=TRange.findText(str);
  166.      if (strFound) {
  167.         //the following line added by Mike and Susan Keenan, 7 June 2003
  168.         win.document.body.scrollTop = TRange.offsetTop;
  169.         TRange.select();
  170.         }
  171.  
  172.  
  173.  
  174.    }
  175.   }
  176.  
  177.    if (TRange==null || strFound==0) {
  178.    TRange=win.document.body.createTextRange();
  179.    dupeRange = TRange.duplicate();
  180.    strFound=TRange.findText(str);
  181.     if (strFound) {
  182.         //the following line added by Mike and Susan Keenan, 7 June 2003
  183.         win.document.body.scrollTop = TRange.offsetTop;
  184.         TRange.select();
  185.         }
  186.  
  187.  
  188.    }
  189.  
  190.  }
  191.  
  192.   if (!strFound) alert ("String '"+str+"' not found!") // string not found
  193.  
  194.  
  195. }
  196. // -->
  197. </script>
  198.  
[HTML]<form name="form1" onSubmit="searc h(document.form 1, frametosearch); return false"><input type="text" name="findthis" size="15" title="Press 'ALT s' after clicking submit to repeatedly search page"> <input type="submit" value="Find in Page" ACCESSKEY="s"></form>
[/HTML]
Thanks,

YaoBao
Feb 8 '08 #1
5 4551
acoder
16,027 Recognized Expert Moderator MVP
JavaScript is best suited to this task. Does this work on a normal HTML page, i.e. not a Coldfusion file?
Feb 8 '08 #2
YaoBao
5 New Member
JavaScript is best suited to this task. Does this work on a normal HTML page, i.e. not a Coldfusion file?

It is work on normal HTML page. But dosn't work with my Coldfusion file. I jsut insert the JavaScript and the FORM above into my coldfusin file. Maybe I missed some code?

Thanks,

YaoBao
Feb 8 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Show the full page code. You can snip the JavaScript part.
Feb 8 '08 #4
YaoBao
5 New Member
It works now. I pasted the code to wrong place. Thank you very much tacking time to help me. Thank you again. YaoBao
Feb 8 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
No problem, glad you managed to fix it. Post again if you have any more questions.
Feb 9 '08 #6

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

Similar topics

2
1568
by: Fabrice Labrousse | last post by:
Hello, Here is a hard problem i cannot solve about window.opener method I think you'll need to be a specialist to find the solution... i can't find the solution by myself ! Please help me. Here is the problem (quiet complicated to explain). I use two differents servers with two IIS 4.0 Web servers On the first one (let's name it Server1) i got my web site. On my web site,
1
1719
by: Anna K. | last post by:
Hi Experts, I'm new to JavaScript and web-based apps development, so I'll tell you right off that I don't really know my way around it as of yet. I'm trying to create a code library set with JavaScript (in DreamweaverMX) to display "buttons" with which to select pages in a gallery. I'm trying to "grey out" (and disable) the button for the current page when it is displayed. (This isn't rocket science here, but it's something that I...
1
1170
by: Les Juby | last post by:
I have an excellent search script which provides the visitor with the searched for text highlighted and positioned within the context of the preceding and following 10 words. However, some of the files we then link to are very big (such as a Parliamentary Act about 30 screens deep) and I'd like to be able to position that page at the point where the searched for text is first found. No problem with passing a variable from the search...
4
2295
by: 28tommy | last post by:
Hi, I'm trying to find scripts in html source of a page retrieved from the web. I'm trying to use the following rule: match = re.compile('<script + src=+>') I'm testing it on a page that includes the following source: <script language="JavaScript1.2"
27
4622
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
1
1266
by: Joey_Stacks | last post by:
I've been searching for an example of a javascript rollover effect, and I'm beginning to think it's impossible, dare I say? Here's what I'm looking for. It's a double rollover effect. You mouseover an image and it swaps the image itself, and editable html text in another location. Here's the catch. The mouseover effect around the image is created in CSS (table border) so there's no need to use dual images for on and off states. The...
1
1971
by: amir | last post by:
Hi, When compiling a page in VS2005 this morning I received 101 messages regarding schema problems in my web.config file. When I go to view an aspx page in my IIS, IE just displays a blank page. I have the June Atlas CTP installed.
2
5088
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!! <!--put the preloads file here as it must load before the website class...
4
68269
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!!
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.