2

I need google translate with my clipboard. so I make some bookmarklet with javascript. but I can't find solution for get data from clipboard.

searching stackoverflow, i find some question using window object and clipboardData.

but chrome has not clipboardData method.

my idea is copy translate source and click bookmarklet( location.href to https://translate.google.co.kr/ and copy clipboard content to textarea#source)

but I don't know how can I access clipboard using javascript.

below my skeleton codes..

  var test = function(){
    changeLocation();
    var content = getClipbord();
    setSource(content);
    };

  var changeLocation = function(){
    location.href="https://translate.google.co.kr/";
  };

  var getClipbord = function(){
    return "";
  };
  var setSource = function(content){
  };
  test();

1 Answer 1

2

If you could access clipboard from JavaScript, it would be a huge security hole.

What you can do with a bookmarklet (and what bookmarklets usually do) is just to pull the selection you marked (without using clipboard at all).

4
  • you said security hole.. I think it is access System problem? Commented May 9, 2014 at 4:59
  • and your solution is something like select text and click right mouse button then 'blah blah' search google...? Commented May 9, 2014 at 5:00
  • No, it is just that any webpage could read your clipboard. Which would be a very bad idea. For example, since I use a password manager, my clipboard very often has a password in it; allowing web-sites access to my clipboard would be spectacularly scary. "Bookmarklet" is normally used for pieces of code that are embedded in an URL and stored in a bookmark; nothing you can access with a right-click.
    – Amadan
    Commented May 9, 2014 at 5:01
  • ah.. i didnt think of password... thanks for your suggestion. Commented May 9, 2014 at 5:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.