copy_paste_example.html
| 1 |
<!DOCTYPE html>
|
|---|---|
| 2 |
<html lang="en"> |
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" /> |
| 5 |
<title>Paste from clipboard</title> |
| 6 |
<script>
|
| 7 |
window.onload=function()
|
| 8 |
{
|
| 9 |
document.oncontextmenu = function()
|
| 10 |
{
|
| 11 |
return true;
|
| 12 |
};
|
| 13 |
|
| 14 |
document.onkeydown = function(event)
|
| 15 |
{
|
| 16 |
// put data to copy on clipboard
|
| 17 |
var inp = document.getElementById("copy");
|
| 18 |
inp.value = "copy to system clipboard";
|
| 19 |
inp.focus();
|
| 20 |
inp.select();
|
| 21 |
|
| 22 |
//ctrl
|
| 23 |
if(event.keyCode == 17)
|
| 24 |
{
|
| 25 |
if (!window.Clipboard)
|
| 26 |
//alert(pasteCatcher)
|
| 27 |
pasteCatcher.focus();
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
//=== Clipboard ================================================================
|
| 32 |
//firefox
|
| 33 |
if (!window.Clipboard)
|
| 34 |
{
|
| 35 |
document.getElementById("copy").focus();
|
| 36 |
}
|
| 37 |
|
| 38 |
// ie, chrome, firefox
|
| 39 |
window.addEventListener("paste", function pasteHandler(e)
|
| 40 |
{
|
| 41 |
alert('paste');
|
| 42 |
if(window.clipboardData)
|
| 43 |
{
|
| 44 |
var txt = window.clipboardData.getData("Text");
|
| 45 |
alert("ie: " + txt);
|
| 46 |
}
|
| 47 |
else if(e.clipboardData)
|
| 48 |
{
|
| 49 |
// get text representation of clipboard
|
| 50 |
var txt = e.clipboardData.getData("text/plain");
|
| 51 |
alert("chrome & firefox & opera: " + txt);
|
| 52 |
}
|
| 53 |
|
| 54 |
e.preventDefault();
|
| 55 |
});
|
| 56 |
|
| 57 |
// ie, chrome, firefox
|
| 58 |
window.addEventListener("copy", function pasteHandler(e)
|
| 59 |
{
|
| 60 |
alert('copy');
|
| 61 |
});
|
| 62 |
|
| 63 |
//=== Clipboard ================================================================
|
| 64 |
|
| 65 |
};
|
| 66 |
</script>
|
| 67 |
</head>
|
| 68 |
<body>
|
| 69 |
<div>Copy CTRL-C / Paste CTRL-V on this page.</div> |
| 70 |
<form name="form" action="#" method="post"> |
| 71 |
<input type="text" name="copy" id="copy" value="" style="opacity:0;position:fixed;top:0px;left:0px;margin-left-20px"/> |
| 72 |
</form>
|
| 73 |
</body>
|
| 74 |
</html>
|