Clipboard access using Javascript - sans Flash?

前端 未结 8 1280
你的背包
你的背包 2020-12-20 13:12

Is there a reliable way to access the client machine\'s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google D

相关标签:
8条回答
  • 2020-12-20 13:30

    Forget pure JS.

    There is no standard API for accessing the clipboard, and few browsers implement a propriety method.

    Flash is the 'standard' method.

    0 讨论(0)
  • 2020-12-20 13:33

    http://www.rodsdot.com/ee/cross_browser_clipboard_copy_with_pop_over_message.asp implements the ZeroClipboard flash object correctly and is cross browser. It also discusses the potential problems with ZeroClipboard and possible work-arounds. Also compatible with Flash 10+.

    0 讨论(0)
  • 2020-12-20 13:43

    Since this is a big security risk, all browsers that care about safety don't allow JS to access the clipboard.

    The main reason is that many people put their passwords into a text file and then use cut&paste to login. Crackers could then collect the password (and possibly other private information like the word document which you just copied) from the clipboard by cracking a popular site and installing some JS that sends them the content of the clipboard.

    Which is why I have flash disabled all the time.

    0 讨论(0)
  • 2020-12-20 13:45

    No, not in FF and Chrome. It works in IE (not sure about 7 and 8, but definitively 6), and from Flash. That is why Flash is always used.

    0 讨论(0)
  • 2020-12-20 13:45

    It was clear this issue, but I still have doubts because there is the option to do this in javascript and another thing is for windows forms it is totally possible to do using the command

    Clipboard.Clear()
    

    Ref: System.Windows.Forms

    Any malicious software that can do well.

    0 讨论(0)
  • 2020-12-20 13:46

    You're looking for the execCommand function, at least the best I can tell. Here are some resources: Insert text in Javascript contenteditable div http://www.java2s.com/Code/JavaScriptReference/Javascript-Methods/execCommandisappliedto.htm

    Unfortunately, this runs into the same security loophole that Flash sealed in Flash 9. Since people were spamming the clipboard, the clipboard is now only accessible through direct user interaction, and honestly, it is better that way. And I'll wager that most browsers have similar (if not stricter policies).

    0 讨论(0)
提交回复
热议问题