Created
May 30, 2012 13:37
-
-
Save lsauer/2836373 to your computer and use it in GitHub Desktop.
Copy to the clipboard in JavaScript, securely and without Flash
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
a{ cursor:pointer; } | |
a, a:link { | |
background-color: #eee; /*#407EC9*/ | |
border-radius:5px; | |
padding:0px 2px 0px 2px; | |
color: #666; | |
font-weight: none; | |
text-decoration: none; | |
opacity:.7; | |
} |
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
<!--// www.lsauer.com lo sauer 2011-2012 | |
//description: various unobtrusive text copy-and-paste methods, which do not require an Adobe-flash plugin | |
//post: | |
//see it in action: http://metgate.org/chrome-session-restore/ | |
//note 'return false' prevents further 'bubbling' of the event, and thus inadvertent window-scrolling. | |
--> | |
<a class="mylink" href="#" onclick="window.prompt('Press CTRL+C, then ENTER',this.innerText); return false;">%HOMEPATH%\AppData\Local\Google\Chrome\User Data\</a> | |
Copy and paste the path into the file-dialog below, to quickly navigate to a specific file. | |
<br> | |
<input type="file"> | |
<!-- | |
Extended to OS-specific behavior with is.lib: | |
<a href="#" onclick="if(is.Linux) this.innerText='~/.config/google-chrome/Default'; | |
window.prompt('Press CTRL+C, then ENTER',this.innerText); return false;" | |
>%HOMEPATH%\AppData\Local\Google\Chrome\User Data\</a> | |
--> | |
<!--Alternative 1: preselected textbox--> | |
<b>Alternative #1 (preselected textbox):</b><br /> | |
<a class="mylink" onclick="this.style.display = 'none'; | |
this.nextElementSibling.style.display = 'inline-block'; | |
this.nextElementSibling.innerText = this.innerText; | |
this.nextElementSibling.select();" | |
>c:\Windows\System32\restore\MachineGuid.txt</a><textarea style="display:none; min-width:33%;" height="1"></textarea> | |
<br /> | |
<!--Alternative 2: direct textbox--> | |
<b>Alternative #2 (direct textbox):</b><br /> | |
<textarea title="Click and press CTRL+C to copy..." onclick="this.style.borderColor = 'orange'; | |
this.select();" style="min-width:33%;" height="1" | |
>c:\Windows\System32\restore\MachineGuid.txt</textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this isn't copying programmatically... you should really change the wording of your description