<html><body>
<script language="JavaScript">
var oWindow = window.external.menuArguments;
var oDocument = oWindow.document;
var oSelect = oDocument.selection;
var oSelectRange = oSelect.createRange();
var sSelText = oSelectRange.text;
var n= oWindow.open( "http://www.merriam-webster.com/dictionary/"+sSelText, "_blank" );
</script>
</body></html>
Description hex decimal
Default 0x01 1 (when no selection; i.e, entire page)
Images 0x02 2
Controls 0x04 4
Tables 0x08 8
Text selection 0x10 16
Anchor 0x20 32
So, if you want the menu item to be available when right-clicking on an Image, you would set the Contexts value to 2. If you want it available when clicking on a text selection OR an Image, set it to 18 (0x12).
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Lookup &Meaning]
@="file://C:\\Program Files\\MyScripts\\LookupMeaning.HTM"
"Contexts"=dword:00000010
var oWindow = window.external.menuArguments;
That provides access to the IE window object. Once you have access to a window object, you can access the document object, and that opens the door to to the entire DOM (Document Object Model) -- so you can do whatever you want. In Example #1, we collect the current text selection, and then open a new window to a dictionary site, passing it the selected text in the URL. The functionality is not particularly convenient because the new page is likely to popup behind the active window (depending on your popup-blocker settings), but it's just an example.
<html><body>
<script language="JavaScript">
var MyDlPath="c:\\temp\\dlPix\\"; // end in \
//-- Get the window and document objects
var oWindow = window.external.menuArguments;
var oDocument = oWindow.document;
//--- get the element on which the mouse was clicked
var x= window.external.menuArguments.event.clientX;
var y= window.external.menuArguments.event.clientY;
var oImg= oDocument.elementFromPoint(x,y);
//var oReq= new oWindow.XMLHttpRequest; // no good: Access Denied!
var oReq = new ActiveXObject( "Microsoft.XMLHTTP" ); // works
oReq.open( "GET", oImg.src, false ); // false= wait for download done
oReq.send(); // it's in cache, so actually no wait...
//------- obtain the original filename
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var sFileName= fso.GetFileName( oImg.src );
var sLocalFile= MyDlPath + sFileName;
//------------------------- rename if already used
if ( fso.FileExists( sLocalFile ) ) {
var oDt= new Date();
var nOffsetDot= sFileName.lastIndexOf(".");
var sFile= sFileName.substring( 0,nOffsetDot );
var sExt= sFileName.substring( nOffsetDot );
sLocalFile= MyDlPath + sFile + oDt.valueOf() + sExt;
}
//-------------- use ADODB (of all things!) to save the file
var adTypeBinary = 1;
var adTypeText= 2;
var adSaveCreateOverWrite= 2;
var oStrm= new ActiveXObject( "ADODB.Stream" );
oStrm.type= adTypeBinary ;
oStrm.open();
oStrm.write( oReq.responseBody );
oStrm.saveToFile( sLocalFile, adSaveCreateOverWrite );
oStrm.close();
</script>
</body></html>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (4)
Commented:
Thanks for the writing. Of course, voted yes.
Ravi.
Commented:
Yes in the top example, you are referring to My Documents
"Open My Documents and create a new folder named MyScripts
Create a new text file in that folder, naming it
LookupMeaning.txt"
later it becomes Program Files
confusing ... :-) However, I got it right.
also you need to bold out 10 only in place of 0x10 in the line
Right-click in the right-hand pane and select New > DWORD Value
set the Name to Contexts and the Value to 0x10 (16).
Thats why I said, fumbled....
One more thing, the reghack needs to be placed just above the manual steps for creating the regedit, I am the type of person who would simply like to merge the stuff to the Registry. I am across it but after practising everything,
Ravi.
Author
Commented:Commented:
Thanks for implementing the suggestions. Regarding the Reghack, you are right, It *is* a tutorial, so it should be that way.
Ravi.