ZeroClipboard 自动复制?
ZeroClipboard autocopy?
ZeroClipboard 是将文本复制到剪贴板的最简单和最好的方法,它使用不可见的 Adobe Flash 影片和 JavaScript 界面。
我试过了,这里有效,代码在这里,如果你想测试它,点击here:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="http://www.paulund.co.uk/playground/demo/zeroclipboard-demo/zeroclipboard/ZeroClipboard.js"></script>
<script>
$(document).ready(function()
{
var clientTarget = new ZeroClipboard( $("#target-to-copy"), {
moviePath: "http://www.paulund.co.uk/playground/demo/zeroclipboard-demo/zeroclipboard/ZeroClipboard.swf",
debug: false
} );
clientTarget.on( "load", function(clientTarget)
{
$('#flash-loaded').fadeIn();
clientTarget.on( "complete", function(clientTarget, args) {
clientTarget.setText( args.text );
$('#target-to-copy-text').fadeIn();
} );
} );
});
</script>
</head>
<body>
<p id="flash-loaded" style="display:none">Flash player is loaded.</p>
<h2>Set Copy Target</h2>
<p>
<button id="target-to-copy" data-clipboard-target="clipboard-text">Click To Copy</button><br/>
<script type="text/javascript">
// What I've done to auto-click
$(document).ready(function(){
$("#target-to-copy").click();
});
</script>
<script>
// What I've done to auto-click
jQuery(function(){
jQuery('#target-to-copy').click();
});
</script>
<textarea name="clipboard-text" id="clipboard-text" >COPY ME PLEASE!!!!!
</textarea>
</p>
<p id="target-to-copy-text" style="display:none;">Text Copied.</p>
<h2>Paste Test</h2>
<textarea name="paste-test" id="paste-test" placeholder="Paste Text Here"></textarea>
我的问题是我想在没有任何用户点击的情况下自动复制到剪贴板。我不打算做坏事(我正在构建一个聊天机器人,我希望他根据用户的请求将文本复制到剪贴板。这就是我尝试过的,在加载时单击带有 id target-to-copy 的按钮,使用 jquery;但没有用。
<script type="text/javascript">
// What I've done to auto-click
$(document).ready(function(){
$("#target-to-copy").click();
});
</script>
<script>
// What I've done to auto-click
jQuery(function(){
jQuery('#target-to-copy').click();
});
</script>
我的猜测是,adobe flash 要求用户实际单击按钮。加载时(自动复制)我的解决方案是什么?正如我之前所说,我正在创建一个智能聊天机器人,用户会与机器人聊天并请求将任何内容复制到剪贴板,然后机器人会响应 jquery 命令以复制到剪贴板,我不希望任何用户点击任何东西。
根据 the ZeroClipboard documentation, 这是不可能的:
Limitations
User Interaction Required
Due to browser and Flash security restrictions, this clipboard injection can ONLY occur when the user clicks on the invisible Flash movie. A simulated click
event from JavaScript will not suffice as this would enable clipboard poisoning.
There are other ways to programmatically set the clipboard text 但它们也需要某种用户交互——例如,Ctrl-C(或 Command-C)。
ZeroClipboard 是将文本复制到剪贴板的最简单和最好的方法,它使用不可见的 Adobe Flash 影片和 JavaScript 界面。
我试过了,这里有效,代码在这里,如果你想测试它,点击here:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="http://www.paulund.co.uk/playground/demo/zeroclipboard-demo/zeroclipboard/ZeroClipboard.js"></script>
<script>
$(document).ready(function()
{
var clientTarget = new ZeroClipboard( $("#target-to-copy"), {
moviePath: "http://www.paulund.co.uk/playground/demo/zeroclipboard-demo/zeroclipboard/ZeroClipboard.swf",
debug: false
} );
clientTarget.on( "load", function(clientTarget)
{
$('#flash-loaded').fadeIn();
clientTarget.on( "complete", function(clientTarget, args) {
clientTarget.setText( args.text );
$('#target-to-copy-text').fadeIn();
} );
} );
});
</script>
</head>
<body>
<p id="flash-loaded" style="display:none">Flash player is loaded.</p>
<h2>Set Copy Target</h2>
<p>
<button id="target-to-copy" data-clipboard-target="clipboard-text">Click To Copy</button><br/>
<script type="text/javascript">
// What I've done to auto-click
$(document).ready(function(){
$("#target-to-copy").click();
});
</script>
<script>
// What I've done to auto-click
jQuery(function(){
jQuery('#target-to-copy').click();
});
</script>
<textarea name="clipboard-text" id="clipboard-text" >COPY ME PLEASE!!!!!
</textarea>
</p>
<p id="target-to-copy-text" style="display:none;">Text Copied.</p>
<h2>Paste Test</h2>
<textarea name="paste-test" id="paste-test" placeholder="Paste Text Here"></textarea>
我的问题是我想在没有任何用户点击的情况下自动复制到剪贴板。我不打算做坏事(我正在构建一个聊天机器人,我希望他根据用户的请求将文本复制到剪贴板。这就是我尝试过的,在加载时单击带有 id target-to-copy 的按钮,使用 jquery;但没有用。
<script type="text/javascript">
// What I've done to auto-click
$(document).ready(function(){
$("#target-to-copy").click();
});
</script>
<script>
// What I've done to auto-click
jQuery(function(){
jQuery('#target-to-copy').click();
});
</script>
我的猜测是,adobe flash 要求用户实际单击按钮。加载时(自动复制)我的解决方案是什么?正如我之前所说,我正在创建一个智能聊天机器人,用户会与机器人聊天并请求将任何内容复制到剪贴板,然后机器人会响应 jquery 命令以复制到剪贴板,我不希望任何用户点击任何东西。
根据 the ZeroClipboard documentation, 这是不可能的:
Limitations
User Interaction Required
Due to browser and Flash security restrictions, this clipboard injection can ONLY occur when the user clicks on the invisible Flash movie. A simulated
click
event from JavaScript will not suffice as this would enable clipboard poisoning.
There are other ways to programmatically set the clipboard text 但它们也需要某种用户交互——例如,Ctrl-C(或 Command-C)。