dsfdsfdsfdsf1223 2016-05-04 03:36
浏览 141
已采纳

Wordpress在播放器旁边播放自定义下载按钮,而不是下载

I asked a friend to add a download button next to the wordpress audio player so that I could easily download each soundtrack.

he wrote these lines of codes in the foother.php for me:

function createMejsDownload(){
    var href = jQuery('.wp-playlist-playing a').attr('href');
    var controllerWidth = jQuery('.mejs-inner').width();
    var controllerWidth2 = controllerWidth-35;
    var html = '<a href="'+href+'" class="mejs-download"></a>';
    jQuery('.mejs-controls').css('width', controllerWidth2+'px');
    jQuery('.mejs-inner').append(html);
    var href = jQuery('.wp-playlist-playing a').attr('href');
    var controllerWidth = jQuery('.mejs-inner').width();
    var controllerWidth2 = controllerWidth-35;
    jQuery('.mejs-controls').css('width', controllerWidth2+'px');
    jQuery('.mejs-time-rail').css('width', (controllerWidth2-174)+'px');
    jQuery('.mejs-time-rail .mejs-time-total.mejs-time-slider').css('width', controllerWidth2-184);
    jQuery('.mejs-download').attr('href', href);
    jQuery('.mejs-controls').trigger('click');
    setInterval(function(){
        var href = jQuery('.wp-playlist-playing a').attr('href');
        var controllerWidth = jQuery('.mejs-inner').width();
        var controllerWidth2 = controllerWidth-35;
        jQuery('.mejs-controls').css('width', controllerWidth2+'px');
        jQuery('.mejs-time-rail').css('width', (controllerWidth2-174)+'px');
        jQuery('.mejs-time-rail .mejs-time-total.mejs-time-slider').css('width', controllerWidth2-184);
        jQuery('.mejs-download').attr('href', href);
        jQuery('.mejs-controls').trigger('click');
    }, 1);
}

The problem is every time I click on the download button it just plays the mp3 file in a new tab instead of downloading. I guess I heard he told me it had something to do with "force_dll" or something but he had no idea how to do that.

I googled for the force_dll issue and I came up with a solution for Google Chrome. it seems like holding alt while clicking on the download button can actually download the file in google chrome but I don't really wanna do things like that! Besides I don't wanna use third party applications as well.

Any help would be appreciated!

展开全部

  • 写回答

1条回答 默认 最新

  • doujianwan7570 2016-05-04 08:47
    关注

    Try this instead:

    function createMejsDownload(){
    var href = jQuery('.wp-playlist-playing a').attr('href');
    var controllerWidth = jQuery('.mejs-inner').width();
    var controllerWidth2 = controllerWidth-35;
    var html = '<a href="'+href+'" class="mejs-download" download></a>';
    jQuery('.mejs-controls').css('width', controllerWidth2+'px');
    jQuery('.mejs-inner').append(html);
    var href = jQuery('.wp-playlist-playing a').attr('href');
    var controllerWidth = jQuery('.mejs-inner').width();
    var controllerWidth2 = controllerWidth-35;
    jQuery('.mejs-controls').css('width', controllerWidth2+'px');
    jQuery('.mejs-time-rail').css('width', (controllerWidth2-174)+'px');
    jQuery('.mejs-time-rail .mejs-time-total.mejs-time-slider').css('width', controllerWidth2-184);
    jQuery('.mejs-download').attr('href', href);
    jQuery('.mejs-controls').trigger('click');
    setInterval(function(){
        var href = jQuery('.wp-playlist-playing a').attr('href');
        var controllerWidth = jQuery('.mejs-inner').width();
        var controllerWidth2 = controllerWidth-35;
        jQuery('.mejs-controls').css('width', controllerWidth2+'px');
        jQuery('.mejs-time-rail').css('width', (controllerWidth2-174)+'px');
        jQuery('.mejs-time-rail .mejs-time-total.mejs-time-slider').css('width', controllerWidth2-184);
        jQuery('.mejs-download').attr('href', href);
        jQuery('.mejs-controls').trigger('click');
    }, 1);
    }
    

    I just added the download to the <a> tag in the 5th line:

     var html = '<a href="'+href+'" class="mejs-download" download></a>';
    

    If that doesn't work, change the 5th line to:

     var html = '<a href="'+href+'" class="mejs-download" target="_blank"></a>';
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部