Hallo.
Is it possible to copy in a WB variable the selected text from a web page edited in Internet Explorer? How?
Take a look at the code included with the IE context menu solution: http://forum.winbatch.com/index.php?topic=313.msg1209#msg1209
You will see the javascript contains commented out code that can get the user selected text. The 'str' variable can then be passed as a commandline parameter to your WinBatch Script. You might also consider changing the registry entry 'Contexts' to the dword value 16. I think this will only display your customized context menu in IE when a user highlights some text on the webpage.
The better solution woud be a WB program; is it no possible to use WB to import a selected text on a web page?
If no, how I can integrate js program with WB program?
A WinBatch script could be used. Would you still like this to launch from the context menu in IE, like your previous posts? IF so simply uncomment the commented code in the javascript then pass the str variable to your WinBatch script.
I have some problems:
- I no know Java script
- I don't know how integrate a JS program with Internet Explorer
- I don't like that solution because generates many program call: JS program call, WB program call and another WB program call to pass the red text.
Is it too much complicate the WB solution?
You could try something like this from a WinBatch script. However I suspect you might run into a security issue with current versions of IE:
;Get Selection Html UNDEBUGGED
html = "NA"
objShell = CreateObject("Shell.Application")
objInstances = objShell.windows
objIE = 0
If objInstances.Count > 0 ; make sure we have instances open.
ForEach objIE In objInstances
sName = StrLower(objIE.FullName)
If StrIndex( sName, 'iexplore.exe', 1, @FWDSCAN ) != 0 ; internet explorer not windows explorer.
ret = AskYesNo( "Found ":objIE.LocationURL, "Would you like to view html?" )
If ret
objInstances = 0
objShell = 0
Break
EndIf
EndIf
Next
EndIf
If objIE == 0
Pause('Notice', 'Unable to locate any running instances of InternetExplorer')
EndIf
objDoc = objIE.Document
;Pause("selection type",objDoc.selection.type)
html = objDoc.selection.createRange().htmlText
Pause('Selected',html )
This seems to work consistently, and is really NOT that difficult to set up. Here is a step by step guide.
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/How~To+Launch~WinBatch~from~Internet~Explorer~Context~Menu~.txt
I tested the script but it seem not work...
Quote from: archimede on October 01, 2013, 05:56:03 AM
I tested the script but it seem not work...
Ok I found a possible issue with the example. Specifically an issue in the HTML using double backslashes.
I tested the revised code with WinBatch 2013C, Windows 7 and IE 10, So I can confirm the process does work. Maybe provide some more details about what does or does not happen when you tried the exact code in the link.
I tested the script in this mode:
- I set some text on THIS page;
- I launced the script in WinBatch Studio; before the firs line I add TimeDelay ( 5 ) to allow launch and set the Internet Explorer window before the program begins;
- while on the TimeDelay ( 5 ) line, I set the Internet Explorer window with the selected text
- the script in WinBatch Studio no shows anything...
I'm not sure the text is right; is it right?
Quote from: archimede on October 01, 2013, 08:28:49 AM
I tested the script in this mode:
- I set some text on THIS page;
- I launced the script in WinBatch Studio; before the firs line I add TimeDelay ( 5 ) to allow launch and set the Internet Explorer window before the program begins;
- while on the TimeDelay ( 5 ) line, I set the Internet Explorer window with the selected text
- the script in WinBatch Studio no shows anything...
I'm not sure the text is right; is it right?
Sorry I thought you were referring to this code:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/How~To+Launch~WinBatch~from~Internet~Explorer~Context~Menu~.txt
The other bit of code (;Get Selection Html UNDEBUGGED) doesn't seem to work with newer version of IE. IT seems to only work with IE 7 and older. Looks like an IE security limitation.
I am trying the js script.
If I have some arguments to add to the .exe application to call, what is the exact syntax?
I am testing this script:
<SCRIPT LANGUAGE="JavaScript">
var parentwin = external.menuArguments; var doc = parentwin.document;
var sel = doc.selection; var rng = sel.createRange(); var str = new String(rng.text);
var oShell = new ActiveXObject("Shell.Application");
oShell.ShellExecute('D:\\Lavori\\Programmi\\WinBatch\\AutoDial Outlook 1.0\\Develope\\Obsolete\\ShowMessage.exe', str);
oShell = null;
</SCRIPT>
ShowMessage.exe is a one-line WB program like this:
Message ( "Test messaggio selezionato in Internet Explorer", "%Param1%" )
The program ShowMessage.exe is called but no arguments are passed; why? Where I mistaked?
Quote from: archimede on October 04, 2013, 02:45:05 AM
I am testing this script:
<SCRIPT LANGUAGE="JavaScript">
var parentwin = external.menuArguments; var doc = parentwin.document;
var sel = doc.selection; var rng = sel.createRange(); var str = new String(rng.text);
var oShell = new ActiveXObject("Shell.Application");
oShell.ShellExecute('D:\\Lavori\\Programmi\\WinBatch\\AutoDial Outlook 1.0\\Develope\\Obsolete\\ShowMessage.exe', str);
oShell = null;
</SCRIPT>
ShowMessage.exe is a one-line WB program like this:
Message ( "Test messaggio selezionato in Internet Explorer", "%Param1%" )
The program ShowMessage.exe is called but no arguments are passed; why? Where I mistaked?
First are you launching the javascript (html) from the IE context menu?
IMPORTANT: Are you selecting any text in IE?
For debugging you might add an alert statement tot he javascript code to ensure that is actual data in the str variable, before you call shellexecute.
Alert(str);
I'm sure, some text is set and the html page is launched from the IE context menu.
If I insert
Alert(str);
before
oShell.ShellExecute(...
when I execute the program opens a message window with this message:
"The value of Alert property is null"
This modified line works properly:
oShell.ShellExecute('D:\\Lavori\\Programmi\\WinBatch\\AutoDial Outlook 1.0\\Develope\\Obsolete\\ShowMessage.exe', "test");
then I think the str value is not properly assigned.
Executing an Internet search I found some technical informations that I integrated with your informations; then I assemblate this working code:
<SCRIPT LANGUAGE="JavaScript">
// 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 sSelectedText = oSelectRange.text;
var oShell = new ActiveXObject("Shell.Application");
oShell.ShellExecute('D:\\Lavori\\Programmi\\WinBatch\\AutoDial Outlook 1.0\\Develope\\Obsolete\\ShowMessage.exe', '"' + sSelectedText + '"');
oShell = null;
</SCRIPT>