Add Search to Internet Explorer context menu

trying to add ‘Search’ menu item in context menu of Internet Explorer 7, so that if I select some text and right click, in the context menu there should be an item ‘Search’ that should open search result in new tab using search engine of your choice.

Adding Entries to the Standard Context Menu

to add Search in context menu, add following registry enrty
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\&Search]
@="file://C:\\scripts\\ie-search.js "

@ represents "Default" key

// Get the window object where the context menu was opened.
var oWindow = window.external.menuArguments;

// Get the document object exposed through oWindow.
var oDocument = oWindow.document;

// Get the selection from oDocument.
// in oDocument.
var oSelect = oDocument.selection;

// Create a TextRange from oSelect.
var oSelectRange = oSelect.createRange();

// Get the text of the selection.
var sNewText = oSelectRange.text;

// If nothing was selected, insert some text.
if (sNewText.length != 0){

 top open in new tab I couldnt find any method
 supported for IE7, so make sure following
 setting is done.

 Tool -> Internet Options -> 
  General Tab
  look for "Change how webpages are displayed in tabs"
  click "Settings" button next to it
  look for "When a opo-up is encountered"
	set "Always open pop-ups in a new tab"

 later on we didnt needed this as open batch file
 will open new url in new tab if IE is already open
   // attempts to open search result in new tab
   //"" + sNewText,"_blank");
   //oWindow.navigate("" + sNewText,"_blank");
   //window.external.NavigateAndFind("" + sNewText, "", "_parent");

   //CScript.CreateObject( "WScript.Shell" ).Run("start " + "" + sNewText);

   // finally this works
   var oShell = new ActiveXObject("Shell.Application"); 
   oShell.ShellExecute("c:/temp/g.bat", sNewText);
        g.bat contains following--

@start /MIN /B

 Copy Enum BrowserNavConstants
     navOpenInNewWindow = 1
     navNoHistory = 2
     navNoReadFromCache = 4
     navNoWriteToCache = 8
     navAllowAutosearch = 16
     navBrowserBar = 32
     navHyperlink = 64
     navEnforceRestricted = 128
     navNewWindowsManaged = 256
     navUntrustedForDownload = 512
     navTrustedForActiveX = 1024
     navOpenInNewTab = 2048
     navOpenInBackgroundTab = 4096
     navKeepWordWheelText = 8192
     navVirtualTab = 16384
     navBlockRedirectsXDomain = 32768
     navOpenNewForegroundTab = 65536
 End Enum

 BrowserNavConstants Enumeration

 Navigate2 - Navigate2 not available


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s