Created
June 14, 2017 16:34
-
-
Save guillaumevincent/de9c5ede4fea4efaa9cd4790f8788bb5 to your computer and use it in GitHub Desktop.
test async copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" | |
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Test</title> | |
</head> | |
<body> | |
<button onclick="copy(genPwd)">copy</button> | |
<script> | |
function genPwd() { | |
return new Promise(function(resolve) { | |
resolve('toto') | |
}) | |
} | |
function copy(p) { | |
p().then(function(result) { | |
console.log('create fake text area'); | |
var fakeTextArea = document.createElement('textarea'); | |
fakeTextArea.setAttribute('readonly', ''); | |
fakeTextArea.value = result; | |
document.body.appendChild(fakeTextArea); | |
fakeTextArea.select(); | |
document.execCommand('copy'); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment