在我的代码中创建多个Zeroclipboard实例化时遇到了问题,每个实例化都会在调用后启动一个弹出窗口。
<a class="xxx" href="popup.url.php" ><span >FRSDE3RD</a>
<a class="xxx" href="popup.url2.php" ><span >FRSDE3RD2</a>
<a class="xxx" href="popup.url3.php" ><span >FRSDE3RD3</a>
$(document).ready(function(){
ZeroClipboard.setMoviePath( 'path/to/swf/ZeroClipboard.swf' );
// setup single ZeroClipboard object for all our elements
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
// assign a common mouseover function for all elements using jQuery
$('a.xxx').mouseover( function() {
// set the clip text to our innerHTML
var url = $(this).attr("href");
var code = $(this).children('span').html();
clip.setText( $(this).children('span').html() );//this.innerHTML );
clip.glue(this);
clip.addEventListener('onMouseDown', function(){
clip.reposition(this);
clip.setText( code );
});
clip.addEventListener('onComplete', function(){
clip.reposition(this);
popUp(url);
});
});
});
function popUp(URL)
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=1024,height=768,left = 328,top = 141');");
}我成功地生成了复制到剪贴板的功能,但如果我使用onMouseUp或onComplete事件来触发弹出功能,它要么像4-5个弹出窗口一样触发,要么根本不触发。
附言:我试着从How to load an Ajax response into clipboard using jQuery and ZeroClipboard?改编解决方案,而不是ajax调用,只是复制到剪贴板上,然后完成午餐弹出窗口...就像我说的那样对我不起作用。
我在启用flashblocker的同时还发现,每次我翻转一个代码标签时,都会在同一地点创建一个新的flash,所以这可能解释了为什么当我点击它时会有3-4个弹出窗口。如果我滚动更多,就会出现更多的弹出窗口。有没有办法阻止flash在同一地点创建或在卷展栏上销毁?
发布于 2010-01-29 17:26:55
经过更多的研究,我找到了这个问题的解决方案:
$("a.xxx").each(function() {
//Create a new clipboard client
var clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
//Glue the clipboard client to the last td in each row
clip.glue(this);
var url = $(this).attr("href");
//Grab the text from the parent row of the icon
var code = $(this).children('span').html();
clip.setText(code);
//Add a complete event to let the user know the text was copied
clip.addEventListener('complete', function(client, text) {
//alert("Copied text to clipboard:\n" + text);
popUp(url);
});
});如果其他人在这个问题上陷入困境,这就是解决方案。
发布于 2014-10-05 16:37:02
尝试使用http://www.steamdev.com/zclip/,它允许您直接访问jquery,并且可以在返回语句中使用自己的逻辑。
包括jquery.zclip.js下载和保存ZeroClipboard.swf
下面是一个代码片段:
$(".class-to-copy").zclip({
path: "assets/js/ZeroClipboard.swf",
copy: function(){
return $(this).attr("data-attribute-with-text-to-copy");
}
});确保更改swf的路径。
发布于 2016-01-21 15:12:32
安德烈·C的回答已经过时了。只需按如下方式操作即可。
<a id="test1" class="test" href="#" data-clipboard-text="1">111</a>
<a id="test2" class="test" href="#" data-clipboard-text="2">111</a>
<a id="test3" class="test" href="#" data-clipboard-text="3">111</a>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="dist1/ZeroClipboard.js"></script>
<script>
var client = new ZeroClipboard( );
client.clip($(".test"));
client.on( "ready", function( readyEvent ) {
client.on( "aftercopy", function( event ) {
alert("Copied text to clipboard: " + event.data["text/plain"] );
} );
});
</script>https://stackoverflow.com/questions/2153246
复制相似问题