It is possible... on trusted sites.
You see, IE's clipboardData is pretty well defined. It supports only text or url.
Neither WScript nor ActiveXObject provide better clipboard access.
But you can use PowerShell to access .Net, including the Clipboard
, which has a nice little method GetImage()
.
Calling PowerShell is simple through WSH, as is Base64 encoding.
Which leaves only the problem of how to retrieve the extracted data.
Normally you should use a file, since we are already using ActiveX.
But for purpose of demonstration, here I will use registry.
This saves us the trouble of creating FileSystemObject
and detecting temp folder.
The html below will grab whatever image is on the clipboard, in base64, and put it into an <img>
.
<!DOCTYPE html><meta charset="utf-8"><img width=500 /><script>
try {
var doc = document, body = doc.body, shell = new ActiveXObject('WScript.shell');
var key = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer';
var cmd = "function Get-ClipImg {Add-Type -AssemblyName 'System.Windows.Forms';"+
"$s=New-Object System.IO.MemoryStream;"+
"[System.Windows.Forms.Clipboard]::GetImage().Save($s,[System.Drawing.Imaging.ImageFormat]::Png);"+
"[Microsoft.Win32.Registry]::SetValue('"+key+"','tmp_clipboard',[System.Convert]::ToBase64String($s.ToArray()))"+
"} Get-ClipImg";
shell.run( 'powershell -Command "'+cmd+'"', 0, true );
var data = shell.RegRead( key + '\\tmp_clipboard' );
shell.RegDelete( key + '\\tmp_clipboard' );
if ( ! data.trim() ) body.textContent = 'Clipboard has no image';
else doc.querySelector('img').src = 'data:image/png;base64,' + data;
} catch ( err ) { body.textContent = err; }
</script>
So, here you are, a way to take clipboard image in IE, without using Flash or Java.
As long as the site is trusted. (Local file included)
Or you can use Flash or Java.