Solved

invoking ctrl-f

Posted on 2004-03-25
3
4,461 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

759 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

21 Experts available now in Live!

Get 1:1 Help Now