Hello all,
I've been building a game that is playable on both mobile and desktop browsers, the issue now is I am trying to create share functionality on the games end screen. I have found useful extensions where I can push users to a social media URL, so that's not a problem.
My main issue is I'm trying to create a button that copies a URL to the user's clipboard so they can share via SMS or however they want. However, gamemaker does not seem to let me do this. Here is my javascript that runs on button click. It is logging the console but not copying text to the clipboard.
var shareLink = document.createElement('textarea');
shareLink.style.visibility = 'fixed';
shareLink.style.top = 0;
shareLink.style.left = 0;
shareLink.style.width = '2em';
shareLink.style.height = '2em';
shareLink.style.padding = 0;
shareLink.style.border = 'none';
shareLink.style.outline = 'none';
shareLink.style.boxShadow = 'none';
shareLink.style.background = 'transparent';
shareLink.value = 'https://www.example.com';
document.body.appendChild(shareLink);
shareLink.select();
document.execCommand('copy');
document.body.removeChild(shareLink);
Let me know if anyone has any solutions or has encountered the same problem.
I've been building a game that is playable on both mobile and desktop browsers, the issue now is I am trying to create share functionality on the games end screen. I have found useful extensions where I can push users to a social media URL, so that's not a problem.
My main issue is I'm trying to create a button that copies a URL to the user's clipboard so they can share via SMS or however they want. However, gamemaker does not seem to let me do this. Here is my javascript that runs on button click. It is logging the console but not copying text to the clipboard.
var shareLink = document.createElement('textarea');
shareLink.style.visibility = 'fixed';
shareLink.style.top = 0;
shareLink.style.left = 0;
shareLink.style.width = '2em';
shareLink.style.height = '2em';
shareLink.style.padding = 0;
shareLink.style.border = 'none';
shareLink.style.outline = 'none';
shareLink.style.boxShadow = 'none';
shareLink.style.background = 'transparent';
shareLink.value = 'https://www.example.com';
document.body.appendChild(shareLink);
shareLink.select();
document.execCommand('copy');
document.body.removeChild(shareLink);
Let me know if anyone has any solutions or has encountered the same problem.