首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zeroclipboard复制文本后切换页面

问Zeroclipboard复制文本后切换页面
EN

Stack Overflow用户
提问于 2012-09-07 01:19:54
回答 1查看 410关注 0票数 0

我看过很多关于zeroclipboard的帖子,但不幸的是,这些回复对像我这样的脚本新手没有帮助(可以理解)。我有一个页面,上面有一堆优惠券。当有人点击优惠券时,我想复制优惠券的代码,然后将他们带到优惠券的链接。我可以将代码复制到警报中,但我不知道如何将它们带到我在每个优惠券链接中指定的url。有人能告诉我怎么做吗?这是我的代码。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2012-09-10 00:33:51

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

在警报代码下面添加如下内容:

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

代码语言:javascript
复制
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);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12305211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档