Author Topic: Copy selected text from edited web page on Internet Explorer  (Read 8897 times)

archimede

  • Newbie
  • *
  • Posts: 22
Copy selected text from edited web page on Internet Explorer
« on: September 29, 2013, 05:23:06 am »
Hallo.
Is it possible to copy in a WB variable the selected text from a web page edited in Internet Explorer? How?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Copy selected text from edited web page on Internet Explorer
« Reply #1 on: September 29, 2013, 07:37:56 am »
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.
Deana F.
Technical Support
Wilson WindowWare Inc.

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #2 on: September 30, 2013, 02:29:59 am »
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?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Copy selected text from edited web page on Internet Explorer
« Reply #3 on: September 30, 2013, 08:49:55 am »
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.
Deana F.
Technical Support
Wilson WindowWare Inc.

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #4 on: September 30, 2013, 08:57:39 am »
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?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Copy selected text from edited web page on Internet Explorer
« Reply #5 on: September 30, 2013, 09:36:24 am »
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:

Code: Winbatch
     
    ;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 )
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Copy selected text from edited web page on Internet Explorer
« Reply #6 on: September 30, 2013, 10:10:53 am »
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
Deana F.
Technical Support
Wilson WindowWare Inc.

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #7 on: October 01, 2013, 05:56:03 am »
I tested the script but it seem not work...

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Copy selected text from edited web page on Internet Explorer
« Reply #8 on: October 01, 2013, 07:49: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.
Deana F.
Technical Support
Wilson WindowWare Inc.

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #9 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?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Copy selected text from edited web page on Internet Explorer
« Reply #10 on: October 01, 2013, 08:58:41 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.
Deana F.
Technical Support
Wilson WindowWare Inc.

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #11 on: October 04, 2013, 01:58:37 am »
I am trying the js script.
If I have some arguments to add to the .exe application to call, what is the exact syntax?

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #12 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?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Copy selected text from edited web page on Internet Explorer
« Reply #13 on: October 04, 2013, 10:31:44 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.
Code: Winbatch
Alert(str);
Deana F.
Technical Support
Wilson WindowWare Inc.

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #14 on: October 04, 2013, 03:06:29 pm »
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.

archimede

  • Newbie
  • *
  • Posts: 22
Re: Copy selected text from edited web page on Internet Explorer
« Reply #15 on: October 04, 2013, 03:35:13 pm »
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>