簡體   English   中英

ZeroClipboard在網站的移動版本上不起作用

[英]ZeroClipboard not working on mobile version of the site

我已經實現ZeroClipboard功能上我們的網站- http://couponvoodoo.com/rcp/Jabong.com/coupons-offers?field_offer_type_tid=All我使用Drupal的7

它在桌面版本上可以正常工作,但在網站的移動版本上不能正常工作。 我將以下代碼放在頁腳中:

<script type="text/javascript">
copy_coupon_footer();
function copy_coupon_footer(){
var divArray = document.getElementsByClassName("unlock_best_coupon");
for (var i = 0, len = divArray.length; i < len; ++i) {
var offer_type = divArray[i].getAttribute('data-clipboard-text');
// alert('offer_type '+offer_type );
try{
       var id = divArray[i].getAttribute( 'id' );
      var client = new ZeroClipboard( document.getElementById(id), {moviePath:'/moviePath' } ); 
      client.on( 'load', function(client) { 
       client.on( 'complete', function(client, args) {try{
      var url = this.getAttribute("href");
       var coupon_code = url.split('&c=')[1].split('&')[0];
       this.innerHTML = coupon_code;
       var classname = this.className+' copied_coupon';
       this.setAttribute("class",classname);
//     window.open(url,'_blank');
     window.location.href = url;
       }catch(e){}
       } );
      } );

     }catch(e){alert(e.message);}
  }
     return false;
  }

</script>

ZeroClipboard需要Adobe Flash才能執行其剪貼板功能,因此,它在任何未安裝Adobe Flash的瀏覽器中均不起作用。

因此,由於幾乎沒有任何具有Adobe Flash的移動設備(只有少數較舊的Android設備),因此無法在移動設備上使用。

當我問這個問題關於不需要Adobe Flash的ZeroClipboard替代方案時,沒有提供其他解決方案。

這個答案可能有點晚了,但是我創建了一個純JavaScript替代zeroclipboard的JavaScript,它非常易於使用。 它是: Github存儲庫 這是代碼:

function clip(text) {   
    var copyElement = document.createElement('input');
    copyElement.setAttribute('type', 'text');
    copyElement.setAttribute('value', text);
    copyElement = document.body.appendChild(copyElement);
    copyElement.select();
    document.execCommand('copy');
    copyElement.remove();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM