سؤال

I have implemented ZeroClipboard functionality on our site - http://couponvoodoo.com/rcp/Jabong.com/coupons-offers?field_offer_type_tid=All I am using Drupal-7

It is working fine on the desktop version but not working on the mobile version of the site. I have put the following code in the footer :

<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 requires Adobe Flash in order to perform it's clipboard function and thus it will not work in any browser that does not have Adobe Flash installed.

So, since there are hardly any mobile devices with Adobe Flash (only a few older Android devices), it won't work on mobile devices.

When I asked this question about an alternative to ZeroClipboard that doesn't require Adobe Flash, no other solutions were offered.

نصائح أخرى

This answer may be a bit late, but I have created a pure JavaScript alternative to zeroclipboard that is very easy to use. Here it is: Github repository. Here is the code:

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 مع الإسناد
لا تنتمي إلى StackOverflow
scroll top