diff --git a/README.md b/README.md index 85df10d..0bfc881 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ copy('Text', { |options.message|Copy to clipboard: `#{key}`, Enter| `String`. Optional. Prompt message. `*` | |options.format|"text/html"| `String`. Optional. Set the MIME type of what you want to copy as. Use `text/html` to copy as HTML, `text/plain` to avoid inherited styles showing when pasted into rich text editor. | |options.onCopy|null| `function onCopy(clipboardData: object): void`. Optional. Receives the clipboardData element for adding custom behavior such as additional formats | +|options.container|document.body| `Element`. | + `*` all occurrences of `#{key}` are replaced with `⌘+C` for macOS/iOS users, and `Ctrl+C` otherwise. @@ -33,7 +35,7 @@ copy('Text', { Works everywhere where `prompt`* is available. Works best (i.e. without additional keystrokes) in Chrome, FF, Safari 10+, and, supposedly, IE/Edge. -Note: **does not work on some older iOS devices.** +Note: **does not work on some older iOS devices.** `*` – even though **Safari 8** has `prompt`, you cannot specify prefilled content for prompt modal – thus it **doesn't work** as expected. # Installation diff --git a/index.js b/index.js index 38b0680..2681185 100755 --- a/index.js +++ b/index.js @@ -23,6 +23,7 @@ function copy(text, options) { selection, mark, success = false; + container = document.body if (!options) { options = {}; } @@ -69,7 +70,7 @@ function copy(text, options) { } }); - document.body.appendChild(mark); + container.appendChild(mark); range.selectNodeContents(mark); selection.addRange(range); @@ -102,7 +103,7 @@ function copy(text, options) { } if (mark) { - document.body.removeChild(mark); + container.removeChild(mark); } reselectPrevious(); }