Solved

invoking ctrl-f

Posted on 2004-03-25
3
4,483 Views
Last Modified: 2012-08-14
I want to open the IE's search window from a link on a HTML page. Is there a way to do this using JavaScript? Sending {CTRL}{F} for exemple.
0
Comment
Question by:Isaac
3 Comments
 
LVL 6

Expert Comment

by:dgelinas
ID: 10677771
Don't think that's possible but you can do this

http://www.javascript-page.com/pgsearch.html
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 250 total points
ID: 10677818
the quick answer to this is basically NO. However here is cross browser code that I use that bascically does the same

<script language="JavaScript">

//Script by GwynforWeb, enjoy and use freely.

// Set browser variables  
var IE4 = (document.all);
var NS4 = (document.layers);

// Set browser window for searching
var win = window;    
var n   = 0;

function FindString(str)
{
 var PageText, Found, i;

 if (str == "")
   return false;
   
 // Sniff for browser
 // Look for match starting at the current point winding around to first match

 if (NS4)
 {
   if (!win.find(str))
     while(win.find(str, false, true))
       n++;
   else
     n++;

   // If not send message.

   if (n == 0)
     alert(" Not Found on Page.");
 }

 if (IE4)
 {
// Set search object to whole page
   PageText = win.document.body.createTextRange();

// Search for nth match from top.
   for (i = 0; i <= n && (Found = PageText.findText(str))  != false; i++)
   {
     PageText.moveEnd("textedit");
     PageText.moveStart("character", 1);
   }

   //  Scroll to and mark text if Found.
   if (Found)
   {
     PageText.moveStart("character", -1);
     PageText.findText(str);
     PageText.scrollIntoView();
     PageText.select();  
     n++;
   }

   // Else, goto top of the page and find first match.

   else
   {
     if (n > 0)
     {
       n = 0;
       FindString(str);
     }

   // Not Found then send message.

     else
       alert("Not Found on Page");
   }
 }

 return false;
}
</script></p>

<form name="Search" onsubmit="return FindString(this.SearchString.value);">
  <p><input onchange="n = 0;" size="17" name="SearchString"> <input type="submit"
  value="Find on Page"> </p>
</form>


0
 

Expert Comment

by:pureandco
ID: 22538069
Thank with a nice script. It work on IE7 but it does not work with firefox 3.0.1. Do you have any suggestion?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now