Chủ Nhật, 29 tháng 7, 2012

Sử dụng Clipboard bằng javascript

Để đưa 1 giá trị text vào clipboard:
  1. window.clipboardData.setData('Text','aaaaaaaa');  
  2.       
Để lấy giá trị text đang lưu trong clipboard:
  1. var value = window.clipboardData.getData("Text");  
  2.       
Tuy nhiên để các hàm này hoạt động thì trình duyệt người dùng phải cho phép sử dụng clipboard. Hiện giờ đa số các trình duyệt đã disable tính năng này vì lý do an ninh hay 1 vài vấn đề khác:

Problems caused by unintended clipboard access

There are several types of problems which can happen if a website is able to use your system's clipboard through javascript:
  • A website may erase the clipboard data, which may cause you to lose important data that you had copied previously into the clipboard.
  • A website may change the clipboard data, which may cause different data to be pasted later on instead of the data you intended to paste originally.
  • A website may read the clipboard data, and use them in malicious ways or send them to a third party without your knowledge.
Therefore, you should only permit the websites that you absolutely trust to be able to access the clipboard.

Không có nhận xét nào :

Đăng nhận xét