Discussion:
Select All and Copy to clipboard web page with VBScript
(too old to reply)
s***@gmail.com
2019-01-30 13:50:40 UTC
Permalink
You can do below way

Set ie = createobject("internetexplorer.application")
Ie.navigate = "yahoo.com"
Do while ie.readystate<>4 :wscript.sleep(100):loop
X=IE.document.body.innertext
Set wsh= createobject ("wscript.shell")
Set clip = wsh.exec("clip")
Clip.stdin.write (X)
Mayayana
2019-01-30 14:30:31 UTC
Permalink
<***@gmail.com> wrote

| You can do below way
|
| Set ie = createobject("internetexplorer.application")
| Ie.navigate = "yahoo.com"
| Do while ie.readystate<>4 :wscript.sleep(100):loop
| X=IE.document.body.innertext
| Set wsh= createobject ("wscript.shell")
| Set clip = wsh.exec("clip")
| Clip.stdin.write (X)

You have numerous errors there. Obviously you never
tried your own code. And why would you want to
transfer webpage text to a console window?

Errors: IE.Navigate is not a property but a method.
There's no "=". document.body only works for quirks mode.
WSHShell is not necessary. You should call Quit on IE
when you're done. It's an application object that runs
in its own process. It doesn't die with your script.

'------------------ begin script ---------------
Dim IE, s1, Ret

Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "C:\windows\desktop\test.html"
Do While IE.ReadyState <> 4
WScript.sleep(100)
Loop

If IE.document.compatMode = "CSS1Compat" Then
s1 = IE.document.documentElement.innerText
Else
s1 = IE.document.body.innerText
End If

Ret = IE.document.parentWindow.clipboardData.setData("Text", s1)

IE.Quit
Set IE = Nothing

' You should now be able to paste the text of the webpage
' to notepad to test that it worked. Or if you have some odd
' reason to use a DOS window then you can try to paste it
' there. :)
JJ
2019-01-31 05:56:54 UTC
Permalink
Post by Mayayana
'------------------ begin script ---------------
Dim IE, s1, Ret
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "C:\windows\desktop\test.html"
Do While IE.ReadyState <> 4
WScript.sleep(100)
Loop
If IE.document.compatMode = "CSS1Compat" Then
s1 = IE.document.documentElement.innerText
Else
s1 = IE.document.body.innerText
End If
Ret = IE.document.parentWindow.clipboardData.setData("Text", s1)
IE.Quit
Set IE = Nothing
' You should now be able to paste the text of the webpage
' to notepad to test that it worked. Or if you have some odd
' reason to use a DOS window then you can try to paste it
' there. :)
Darn it. I use "HTMLFile" object to read the clipboard like below.

txt = createobject("htmlfile").parentwindow.clipboarddata.getdata("text")
wsh.echo txt

And I thought I could simply use `putData()`, but it doesn't do anything.

Using "InternetExplorer.Application" works, but I have IE11, and since IE7,
clipboard access is protected. Local files are categorized as "My Computer"
zone, and don't have access to the clipboard. The only zone which default to
allow clipboard access is the Local Intranet zone. However, local file paths
can't be added into its list of sites. So, my only solution is to add
"about:blank" into the list, and use that URL in the script.

It's funny that the "HTMLFile" object have read access to the clipboard. If
it can read the clipboard, it should be able to write the clipboard, right?
Or is it a security hole? If it's not a security hole, how to get write
access to the clipboard?
Evertjan.
2019-01-31 08:59:44 UTC
Permalink
Post by JJ
Post by Mayayana
'------------------ begin script ---------------
Dim IE, s1, Ret
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "C:\windows\desktop\test.html"
Do While IE.ReadyState <> 4
WScript.sleep(100)
Loop
If IE.document.compatMode = "CSS1Compat" Then
s1 = IE.document.documentElement.innerText
Else
s1 = IE.document.body.innerText
End If
Ret = IE.document.parentWindow.clipboardData.setData("Text", s1)
IE.Quit
Set IE = Nothing
' You should now be able to paste the text of the webpage
' to notepad to test that it worked. Or if you have some odd
' reason to use a DOS window then you can try to paste it
' there. :)
Darn it. I use "HTMLFile" object to read the clipboard like below.
txt =
createobject("htmlfile").parentwindow.clipboarddata.getdata("text")
wsh.echo txt
And I thought I could simply use `putData()`, but it doesn't do anything.
Using "InternetExplorer.Application" works, but I have IE11, and since
IE7, clipboard access is protected. Local files are categorized as "My
Computer" zone, and don't have access to the clipboard. The only zone
which default to allow clipboard access is the Local Intranet zone.
However, local file paths can't be added into its list of sites. So, my
only solution is to add "about:blank" into the list, and use that URL in
the script.
It's funny that the "HTMLFile" object have read access to the clipboard.
If it can read the clipboard, it should be able to write the clipboard,
right? Or is it a security hole? If it's not a security hole, how to get
write access to the clipboard?
I use this javascript script in my html to copy a textnode to the clipboard,
perhaps you can convert it to vbs?:

<script type='text/javascript'> 'use strict'

function toClipboard(t) {
let s = window.getSelection();
s.removeAllRanges();
let range = document.createRange();
range.selectNode(t);
s.addRange(range);
document.execCommand("Copy");
};

</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
JJ
2019-02-01 08:44:53 UTC
Permalink
Post by Evertjan.
I use this javascript script in my html to copy a textnode to the clipboard,
<script type='text/javascript'> 'use strict'
function toClipboard(t) {
let s = window.getSelection();
s.removeAllRanges();
let range = document.createRange();
range.selectNode(t);
s.addRange(range);
document.execCommand("Copy");
};
</script>
Odd. The `createRange()` method doesn't exist.

set ie = createobject("internetexplorer.application")
ie.visible = 0
ie.navigate "about:blank"
do while ie.readystate <> 4
wsh.sleep 100
loop
set sel = ie.document.parentwindow.getselection()
set rng = sel.createrange() 'error
JJ
2019-02-01 09:05:04 UTC
Permalink
Post by JJ
Odd. The `createRange()` method doesn't exist.
set ie = createobject("internetexplorer.application")
ie.visible = 0
ie.navigate "about:blank"
do while ie.readystate <> 4
wsh.sleep 100
loop
set sel = ie.document.parentwindow.getselection()
set rng = sel.createrange() 'error
Oh, nevermind. I use an anlternative method by creating an INPUT element,
set its value, select the text, then use `ExecCommand()`. Turns out that the
"Copy" command is also protected. I think using IE object is not an option
anymore.
Mayayana
2019-02-01 13:46:28 UTC
Permalink
"JJ" <***@vfemail.net> wrote

| Odd. The `createRange()` method doesn't exist.
|

It does. But getSelection doesn't. createRange
probably failed because you didn't have a selection
object.
I'm guessing Evertjan may have been pasting a
javascript browser scripting standard that doesn't
exist in IE and didn't realize his code wasn't relevant.
He also, apparently, didn't test it.
Evertjan.
2019-02-01 21:55:04 UTC
Permalink
Post by Mayayana
| Odd. The `createRange()` method doesn't exist.
|
It does. But getSelection doesn't. createRange
probably failed because you didn't have a selection
object.
I'm guessing Evertjan may have been pasting a
javascript browser scripting standard that doesn't
exist in IE and didn't realize his code wasn't relevant.
He also, apparently, didn't test it.
The Javascript script I showed works very well on browsers
that support Javascript strict, no neeed for me to test that.

Seems you assume a lot about others, I assume,
and wrongly state that as apparent.

There is no "browser scripting standard".

As I indicated, I gave the javascript script for consideration,
and presumed that this possibly was about Cscript/Jscript,
and evenso, IE has, I presume, no strict javascript, only Jscript.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mayayana
2019-02-02 00:14:33 UTC
Permalink
"Evertjan." <***@inter.nl.net> wrote

| The Javascript script I showed works very well on browsers
| that support Javascript strict, no neeed for me to test that.
|

Except this is a VBScript group and we're talking about
IE. If you can't be botherd to test the script you post
then it might be better to just not post it.

| There is no "browser scripting standard".
|

There is standard DOM, which is not the same as
IE DOM. That's why my original sample tested for
quirks mode. You've demonstrated yourself that
you use window.getSelection. Did you not know that
IE doesn't support any version of getSelection before IE9?
And according to what I can find, window.getSelection
is not recommended because it's not consistently
supported, but document.getSelection is in IE9+ and
other browsers.


| As I indicated, I gave the javascript script for consideration,
| and presumed that this possibly was about Cscript/Jscript,

?? It's a VBScript group and we were talking about a
VBScript way to get clipboard data via IE.
Evertjan.
2019-02-02 14:17:21 UTC
Permalink
Post by Mayayana
| The Javascript script I showed works very well on browsers
| that support Javascript strict, no neeed for me to test that.
|
Except this is a VBScript group and we're talking about
IE. If you can't be botherd to test the script you post
then it might be better to just not post it.
How nice that you don't define netiquette.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
JJ
2019-02-01 22:20:57 UTC
Permalink
Post by Mayayana
It does. But getSelection doesn't. createRange
probably failed because you didn't have a selection
object.
You're right. I thought `getSelection()` returned an object because when I
use `typename()` to check it, it doesn't return `Empty`. That was my
mistake. `VarType()` actually returns 8 ([IUnknown] interface) instead of 10
(object / IDispatch interface). No wonder VBScript can't access any of its
member.
Post by Mayayana
I'm guessing Evertjan may have been pasting a
javascript browser scripting standard that doesn't
exist in IE and didn't realize his code wasn't relevant.
He also, apparently, didn't test it.
Yes, I noticed that too, since his code uses `removeAllRanges()` which MSIE
doesn't have.
R.Wieser
2019-01-31 09:03:15 UTC
Permalink
JJ,
how to get write access to the clipboard?
When I tried to play the "go thru IE" game on W98 I noticed it being
non-stable at best (IIRC could not (even) find a dependable way to have IE
close down nicely after usage). When the need for clipboard access came up
I therefore decided to create COM object which accessed the clipboard
directly instead.
it should be able to write the clipboard, right? Or is it a security hole?
Most likely. The user copying an URL and a script than surreptiously
replace it with a different one would be one of the possible tricks ....

But it could also be related to some "protection" scripts which would try to
twart any copy-pasting by the user by continuously emptying the clipboard
(and as the clipboard is system-wide you can guess the negative effects for
users not just concentrating on browsing ...).

Regards,
Rudy Wieser
Mayayana
2019-01-31 14:05:38 UTC
Permalink
This post might be inappropriate. Click to display it.
Mayayana
2019-01-31 16:14:27 UTC
Permalink
This post might be inappropriate. Click to display it.
JJ
2019-02-01 09:30:38 UTC
Permalink
Post by Mayayana
An addendum. I was looking in '98 MSDN for OLECMDID.
I just opened the Win7 version of MSDN and found a
bigger list. Much of it doesn't look very useful and may
be mostly for the WB control, but for what it's worth....
Interestingly, there are a lot of gaps in the numbering,
such as with 34-48. Maybe there are some hidden goodies.
[snip]

I wouldn't be surprised if there is. It's a Microsoft product after all. :)
JJ
2019-02-01 09:28:42 UTC
Permalink
Post by Mayayana
I don't know about security for the following, but you
can try it. It's a cleaner version of Evertjan's javascript
method. (Who knew there were so many options?!)
execCommand deals with the DOM. The cut/copy/paste
options are odd in that context, since that kind of thing
can be done with a Textrange. But there they are.
Dim IE, s1, Ret
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "C:\windows\desktop\test.html"
Do While IE.ReadyState <> 4
WScript.sleep(100)
Loop
IE.ExecWB 17, 2 '-- select all. don't prompt user.
IE.ExecWB 12, 2 '-- copy. don't prompt user.
IE.Quit
Set IE = Nothing
Great! It works. Thank you.

I didn't know `ExecWB()` has a higher security access.
Mayayana
2019-02-01 13:49:15 UTC
Permalink
"JJ" <***@vfemail.net> wrote

| I didn't know `ExecWB()` has a higher security access.

Neither did I. It doesn't make much sense, does it?
Either way, you're controlling the instance. I guess it's
because the clipboard methods come from the window
object, which is accessible in DOM scripting, while the
IE object is not. A remote website can access the DOM but
can't access the IE object.
Dave "Crash" Dummy
2019-01-31 14:06:31 UTC
Permalink
Post by s***@gmail.com
You can do below way
Set ie = createobject("internetexplorer.application")
Ie.navigate = "yahoo.com"
Do while ie.readystate<>4 :wscript.sleep(100):loop
X=IE.document.body.innertext
Set wsh= createobject ("wscript.shell")
Set clip = wsh.exec("clip")
Clip.stdin.write (X)
This is why I hate Google Groups.
--
Crash

When it comes to texting, some people are all thumbs.
Loading...