<a href="javascript:SelectContents('ipwd')">Select and Copy Password</a>
<script language=javascript>
function SelectContents(ilink)
{
document.getElementById("ilink").select();
var copyrange=document.getElementById("ilink").createTextRange();
copyrange.execCommand("Copy");
}
</script>
<html>
the above code copies contents from the textarea when we click on the "selelct all" anchor tag. But sadly this code works only for IE browser.how to ensure that this works for mozilla also. thanks for any help.
Browsers other than IE have NO ACCESS to the clipboard since it isn't part of your web page and the operating system may not even have such a thing.
You can enable it in the browser when you are using Firefox on an intranet but it is a security risk to do sofor the internet.
your'e gonna love this one felgall!
it works in firefox (or any browser really) to set the clipboard, no user config changes needed!
it is also nice that it requires no user confirmation or warning about the clipboard, simply sets the text.
big downside is that is limited to the amount of into it can handle. this varies by browser, but should always be at least 2kb.
use like: copy(document.getElmementById("ilink").value);
-----
one more thing (about the non-flash way):
i made the config change to unlock the clipboard in firefox a long time ago.
just change signed.applets.codebase_principal_support to true in about:config.
it's not a security risk (imho) because you still get a confirmation prompt whenever a site tries to get to the clipboard.
i have NEVER had the confirm box pop-up on a page i didn't expect it to.
if it ever did, i would simply click "no", and the javascript would get denied clipboard access.
That is flash accessing the clipboard - not JavaScript.
It wouldn't work on ANY of the browsers on my computer because I have Flash turned off.
It also wouldn't work on any operating system that doesn't have a clipboard or where the browser doesn't support flash (which would include most browsers not running on a computer).
Hi,
in this link ,"http://developer.mozilla.org/en/Using_the_Clipboard",i found the following code:
const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString("Put me on the clipboard, please.");
PHP is running on the server and there isn't a clipboard on the web server for it to access (there may be a clipboard on the computer itself but the web server software can't access it).
That is flash accessing the clipboard - not JavaScript.
It wouldn't work on ANY of the browsers on my computer because I have Flash turned off.
It also wouldn't work on any operating system that doesn't have a clipboard or where the browser doesn't support flash (which would include most browsers not running on a computer).
I know it's not javascript, but a lot more people have flash (~90%) than a non IE browser (~35%).
didn't consider OS, what OS doesn't have a clipboard?
OP:
throw the copy function somewhere along side your other functions in the script.
then replace the function SelectContents with this new one:
Code:
function SelectContents(ilink)
{
var elm = document.getElementById("ilink");
elm.select();
if(window.ActiveXObject){
var copyrange=document.getElementById("ilink").createTextRange();
copyrange.execCommand("Copy");
} else {
copy(elm.value);
}
}
Bookmarks