-
کد کپی و پیست
سلام
من میخوام وقتی کاربر روی یه دکمه کلیک میکنه یه متن براش کپی شه و بتونه اون رو جای دیگه ای (خودش) پیست کنه!
یه کد دیگه هم برای پیست می خوام که وقتی روی کلید ، کلیک میکنم اون چیزی که کپی شده داخل یه text box بنویسه...
اگه میشه کمک کنین...
ممنون :40:
-
[HTML]<head>
<script>
function CopyToClipboard () {
var input = document.getElementById ("toClipboard");
window.clipboardData.setData ("Text", input.value);
}
function ShowClipboardContent () {
alert (window.clipboardData.getData ("Text"));
}
function ClearClipboard () {
window.clipboardData.clearData ("Text");
}
</script>
</head>
<body>
<input id="toClipboard" value="text to clipboard"/>
<button onclick='CopyToClipboard ()'>Copy text to clipboard</button>
<br /><br />
<button onclick='ShowClipboardContent ();'>Show text data in clipboard</button>
<button onclick='ClearClipboard ();'>Clear text data from clipboard</button>
</body>[/HTML]
[HTML]<head>
<script>
function CopyToClipboard () {
var input = document.getElementById ("toClipboard");
var textToClipboard = input.value;
var success = true;
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData ("Text", textToClipboard);
}
else {
// create a temporary element for the execCommand method
var forExecElement = CreateElementForExecCommand (textToClipboard);
/* Select the contents of the element
(the execCommand for 'copy' method works on the selection) */
SelectContent (forExecElement);
// Copy the selected content to the clipboard
try {
// Works in Safari, throws an exception in Firefox and Opera
document.execCommand ("copy", false, null);
} catch (e) {
try {
// Works in Firefox, throws an exception in Opera
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
document.execCommand ("copy", false, null);
} catch (e) {
success = false;
}
}
// remove the temporary element
document.body.removeChild (forExecElement);
}
if (success) {
alert ("The text is on the clipboard, try to paste it!");
}
else {
alert ("Your browser doesn't allow clipboard access!");
}
}
function CreateElementForExecCommand (textToClipboard) {
var forExecElement = document.createElement ("div");
// place outside the visible area
forExecElement.style.position = "absolute";
forExecElement.style.left = "-10000px";
forExecElement.style.top = "-10000px";
// write the necessary text into the element and append to the document
forExecElement.textContent = textToClipboard;
document.body.appendChild (forExecElement);
// the contentEditable mode is necessary for the execCommand method in Firefox
forExecElement.contentEditable = true;
return forExecElement;
}
function SelectContent (element) {
// first create a range
var rangeToSelect = document.createRange ();
rangeToSelect.selectNodeContents (element);
// select the contents
var selection = window.getSelection ();
selection.removeAllRanges ();
selection.addRange (rangeToSelect);
}
</script>
</head>
<body>
<input id="toClipboard" value="text to clipboard"/>
<button onclick='CopyToClipboard ()'>Copy text to clipboard</button>
</body>[/HTML]
:46:
---------- Post added at 09:19 PM ---------- Previous post was at 09:18 PM ----------
[HTML]<script type="text/javascript" language="javascript">
function copyText()
{
var copyDivText = document. getElementById( 'div1' ) .innerText;
var returnVal = window. clipboardData. setData( 'Text', copyDivText );
alert(returnVal);
document. getElementById( 'div2' ). innerText = window. clipboardData. getData( 'Text' );
}
</script>
<div id="div1">
Copy this text to the clipboard using javascript
</div>
<br />
<input type="button" id="btn" value="copy" onclick="copyText()">
<br />
<div id="div2">
</div>[/HTML]
---------- Post added at 09:19 PM ---------- Previous post was at 09:19 PM ----------
[HTML]<script type="text/javascript" language="javascript">
function copyText()
{
var copyDivText = document. getElementById( 'div1' ) .innerText;
var returnVal = window. clipboardData. setData( 'Text', copyDivText );
alert(returnVal);
document. getElementById( 'div2' ). innerText = window. clipboardData. getData( 'Text' );
}
</script>
<div id="div1">
Copy this text to the clipboard using javascript
</div>
<br />
<input type="button" id="btn" value="copy" onclick="copyText()">
<br />
<div id="div2">
</div>[/HTML]