Zeroclipboard复制文本后切换页面

时间:2012-09-06 17:19:54

标签: javascript zeroclipboard

我看过很多关于zeroclipboard的帖子,但不幸的是回复对像我这样的脚本新手没有帮助(可理解)。我有一个页面上有一堆优惠券。当有人点击优惠券时,我想复制优惠券的代码,然后将它们带到优惠券的LINK。我可以在警报中复制CODE,但我无法弄清楚如何将它们带到我在每个优惠券的LINK中指定的URL。有人能告诉我一种方法吗?这是我的代码......

<section style="position:relative">
<div id="sliders" style="margin:0 auto; width: auto; height:auto;">
    <div class="scrollable" id="scrollable">
        <div id="slider1" class="items">

            <div onclick="window.open('http://url-one.com','_blank');"> <!--THERE ARE SEVERAL OF THESE-->
                html...
                <div id="clip_container1">
                    <p id="coupon1" link="url-one.com" onMouseOver="move_swf(this)">copytext1</p>
                </div>
            </div>

        </div>
    </div>
</div>
</section>

<script>
ZeroClipboard.setMoviePath( '<?= base_url("resource/js/ZeroClipboard.swf");?>' );
var clip = null;
//  function $(id) { return document.getElementById(id); } //not needed?
function init() 
{
    clip = new ZeroClipboard.Client();
    clip.setHandCursor( true );
    clip.addEventListener('complete', function(client, text) {
        alert("Copied Coupon Code to your clipboard:\n" + text);
//          now open "link" in a new window...;   
    });
   }

function move_swf(ee)
{ 
   copything = document.getElementById(ee.id+"").innerHTML;
   clip.setText(copything.substring(23));
      if (clip.div)
     {    
         clip.receiveEvent('mouseout', null);
         clip.reposition(ee.id);
      }
      else{ clip.glue(ee.id);   
      }
      clip.receiveEvent('mouseover', null);
 }    
window.onload = init;
</script>

1 个答案:

答案 0 :(得分:0)

通过其中包含的优惠券代码获取所需的DOM元素 (假设优惠券代码是唯一的)

在警报代码下方添加以下内容:

(假设我添加的代码行中有jquery):

clip.addEventListener('complete', function(client, text) {
    alert("Copied Coupon Code to your clipboard:\n" + text);

    //Add the two lines below

    var mylink = jQuery( "p:contains(" + text + ")" ).attr('link'); 
    myWhateverOpenSesameFunctionToOpenMyLink(mylink);
});