Zeroclipboard 多个元素

发布于 2024-08-19 06:45:18 字数 1911 浏览 4 评论 0原文

我在代码中创建多个 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 个弹出窗口一样触发,要么根本不触发。

PS我尝试调整 的解决方案如何使用 jQuery 和 ZeroClipboard 将 Ajax 响应加载到剪贴板? 而不是 ajax 调用,只需复制到剪贴板并在完成午餐时弹出一个弹出窗口...正如我所说,这对我不起作用。

在启用 flashblocker 时我还发现,每次我翻转 CODE 标签时,都会在同一位置创建一个新的 flash,因此这可能可以解释为什么当我单击它时会出现 3-4 个弹出窗口。如果我滚动更多,就会出现更多弹出窗口。有没有办法阻止闪光灯在同一位置创建或在推出时销毁?

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

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.

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放飞的风筝 2024-08-26 06:45:18

经过更多研究,我找到了这个问题的解决方案:

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

如果其他人遇到这个问题,这就是解决方案。

after more research I got to my solution to this problem:

$("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.

昇り龍 2024-08-26 06:45:18

尝试使用 http://www.steamdev.com/zclip/ 它允许您直接访问 jquery 和您可以在 return 语句中使用自己的逻辑。

包含 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 的路径。

Try using http://www.steamdev.com/zclip/ it allows you direct access to jquery and you can use your own logic in the return statement.

include jquery.zclip.js
download and save ZeroClipboard.swf

Here is a snippet:

$(".class-to-copy").zclip({
    path: "assets/js/ZeroClipboard.swf",
    copy: function(){
        return $(this).attr("data-attribute-with-text-to-copy");
    }
});

Make sure you change the path of the swf.

绝對不後悔。 2024-08-26 06:45:18

Andrei 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>

What Andrei C answered is outdated.
Just do it as follows.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文