Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

invoking ctrl-f

Posted on 2004-03-25
3
Medium Priority
?
4,594 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

877 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