Not able to access window.clipboard in unsecured websites.

Discuss various technical topics not related to Mozilla.
Post Reply
santhosha
Posts: 3
Joined: December 21st, 2018, 5:48 am

Not able to access window.clipboard in unsecured websites.

Post by santhosha »

Hello,

can you please suggest me how to enable window.clipboard in unsecured web pages, currently i have a project where i need to copy selected text and paste it in somewhere. So am using document.execCommand("copy"); but am not able to find window.clipboard in developer tool. So not able to copy the things to clipboard.
Or suggest how can I enable it using javascript.
User avatar
DanRaisch
Moderator
Posts: 127234
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Not able to access window.clipboard in unsecured website

Post by DanRaisch »

Moving to MozillaZine Tech as this is not a Firefox issue.
santhosha
Posts: 3
Joined: December 21st, 2018, 5:48 am

Re: Not able to access window.clipboard in unsecured website

Post by santhosha »

where should i post? @DanRaisch
User avatar
DanRaisch
Moderator
Posts: 127234
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Not able to access window.clipboard in unsecured website

Post by DanRaisch »

You don't need to do anything as I've already moved your post to the more appropriate location.
santhosha
Posts: 3
Joined: December 21st, 2018, 5:48 am

Re: Not able to access window.clipboard in unsecured website

Post by santhosha »

Ok, Thnak you @DanRaisch, tell me Where can i get the update?
User avatar
DanRaisch
Moderator
Posts: 127234
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Not able to access window.clipboard in unsecured website

Post by DanRaisch »

You're welcome.
To what update are you referring?
User avatar
mightyglydd
Posts: 9813
Joined: November 4th, 2006, 7:07 pm
Location: Hollywood Ca.

Re: Not able to access window.clipboard in unsecured website

Post by mightyglydd »

#KeepFightingMichael and Alex.
Tomatoshadow2
Posts: 435
Joined: May 11th, 2017, 9:52 am

Re: Not able to access window.clipboard in unsecured website

Post by Tomatoshadow2 »

@mightyglydd =D> :lol:
morat
Posts: 6429
Joined: February 3rd, 2009, 6:29 pm

Re: Not able to access window.clipboard in unsecured website

Post by morat »

Are you using the clipboard code with a click handler?

I tried the following code in the error console.

Code: Select all

function readFromClipboard() {
  var element = document.createElement("textarea");
  document.body.appendChild(element);
  element.focus();
  element.select();
  document.execCommand("paste", false, null);
  element.remove();
  return element.value;
}
function writeToClipboard(text) {
  var element = document.createElement("textarea");
  document.body.appendChild(element);
  element.value = text;
  element.focus();
  element.select();
  document.execCommand("copy", false, null);
  element.remove();
}
writeToClipboard("abracadabra");
It works in Chrome, but not in Firefox.
document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler
More info
http://stackoverflow.com/questions/41094318
Post Reply