2012-02-21

SCRIPT - 實現跨瀏覽器的「複製」文字功能



step 1. import jquery.js & clip.js



step 2. 複製的 button (這裡的 id 要跟 step3 的識別名稱相同)


step 3. 執行的 script (放在 </body> 之前)
jQuery(document).ready(function(){
    jQuery('#sbtn_copy').mouseover(function(){
        if (jQuery(this).data('clipboard-loaded')) {
            return;
        }
        jQuery(this).data('clipboard-loaded', true);
        ZeroClipboard.setMoviePath('/_public/_swf/clip.swf');
        var clip = new ZeroClipboard.Client();
        clip.setHandCursor(true);
        clip.addEventListener('onMouseDown', function(client) {
            clip.setText('<{$embedUrl}>');
        });
        clip.addEventListener('onComplete', function(client) {
            alert('複製完成');
        });
        clip.glue('sbtn_copy');
    });
});




沒有留言:

張貼留言