Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var copy = function(opts) {
- if (typeof opts === 'string') {
- opts = {
- content: opts,
- mimetype: 'text/plain'
- };
- }
- var frame = document.createElement("iframe");
- document.body.appendChild(frame);
- try {
- frame.contentDocument.designMode = "on";
- /*
- # if html is opts.type
- # frame.setAttribute "sandbox", "allow-same-origin"
- # frame.contentDocument.documentElement.innerHTML = opts.content
- # frame.contentDocument.execCommand "selectAll", not 1, null
- # else
- */
- frame.contentDocument.oncopy = function(b) {
- b.clipboardData.setData(opts.mimetype || "text/plain", opts.content);
- return b.preventDefault();
- };
- frame.contentDocument.execCommand("copy", !1, null);
- frame.contentDocument.designMode = "off";
- } catch (err) {
- console.error("Couldn\'t copy the text!");
- }
- frame.parentNode.removeChild(frame);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement