dsfdsfdsfdsf1223 2016-05-04 11: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 16: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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?