1

How can I use clipboardData.getData to return the file path of a file I have copied to my clipboard? (Internet Explorer)

Example:

1) user copies word document on desktop to clipboard

2) user right clicks on my web page and clicks "paste"

3) web page captures the file path of the document that was on the clipboard

I have tried using clipboardData.getData but it returns "null" when I paste a document

SPBeginner
  • 11
  • 1
  • 3

2 Answers2

0

The answer is simple: it is impossible.

This information is not accessable, because the browser lives in a sandbox.

This is the API: http://www.w3.org/TR/FileAPI/#dfn-file

Detecting local file drag'n'drop with HTML/JavaScript

Community
  • 1
  • 1
Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79
  • Thank you for your reply. Based on your answer, is copy/pasting files into IE impossible altogether? (Excluding drag and drop) – SPBeginner Mar 18 '13 at 21:52
  • Thought it was about drag and drop. I don't know about the clipboard. But I think it will be the same interface for files as DnD – Christian Kuetbach Mar 18 '13 at 22:03
0

Here is how I do images.

Instead of [RightClick-Copy], do [SHIFT-RightClick-Copy as Path] while the mouse pointer is over a local PC image.

var MYIMAGE = window.clipboardData.getData('text');

MYIMAGE will now have the path to the local photo. Using the replace() javascript function:

  1. Change C: to \C$ in the string.
  2. Add the local computer name to the beginning of the string.
  3. Add \\ before the computer name you just added to the string.

You now have a new path to the local file that IE will recognize. To paste it...

document.getElementById("whateverIDyoucalledit").src = MYIMAGE;
Paul Roub
  • 36,322
  • 27
  • 84
  • 93