Zeroclipboard多个元素 [英] Zeroclipboard multiple elements

查看:197
本文介绍了Zeroclipboard多个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中创建多个Zeroclipboard实例化时遇到问题,每个实例化在调用后都会启动一个弹出式窗口。

I'm having trouble creating multiple Zeroclipboard instantiations in my code, with each instantiation launching a popup window after it is invoked.

<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个弹出窗口或者不触发。

I succeed on generating the copy to clipboard functionality, but if I use either onMouseUp, onComplete events to trigger popup function, it either fire like 4-5 popups or doesn't fire at all.

PS我尝试从更改解决方案使用jQuery和ZeroClipboard将一个Ajax响应加载到剪贴板?而不是ajax调用只是复制到剪贴板和完成午餐一个弹出...,因为我说没有为我工作。

P.S. I tried to adapt the solution from How to load an Ajax response into clipboard using jQuery and ZeroClipboard? instead of ajax call just copy to clipboard and on complete to lunch a popup ... as I said didn't worked for me.

在启用flashblocker的时候,我想到的是,每次我滚动一个CODE标签,一个新的闪存正在同一地点创建,这可能是一个解释为什么我有3 -4弹出时,我单击它。如果我滚滚更多,更多的弹出窗口来了。有没有办法阻止闪光灯在同一地点创建或销毁?

What else I figured it out while having flashblocker enabled is that every time I rollover a CODE tag a new flash is being created on the same spot so this might be an explanation why I'm having 3-4 popup when I click it. If I rollover more, more popups come. Is there a way to stop the flash from creating on same spot or destroy on rollout?

推荐答案

解决这个问题:

$("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);
  });
});

这是解决方案,如果任何人都会遇到这个问题。

this is the solution if anyone else will get stuck on this problem.

这篇关于Zeroclipboard多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆