2016-03-04 91 views
0

我使用以下WordPress管理通知来提示用户下载某些文件。我希望在下载文件时包含进度条或至少包含“正在下载 - 请稍候”消息。在文件下载时显示“请稍候”消息或进度条

任何想法?

我试过几个jQuery解决方案,但可能没有任何工作。当谈到jQuery时,我总是不喜欢。

/* Ask user to download GeoIP database files. */ 
add_action('admin_notices', 'lsmi_dl_admin_notice'); 
add_action('network_admin_notices', 'lsmi_dl_admin_notice'); // also show message on multisite 
function lsmi_dl_admin_notice() { 
    $dir = dirname(__FILE__); 
    $localfilev4 = $dir . '/data/GeoIPv4.dat'; 
    $localfilev6 = $dir . '/data/GeoIPv6.dat'; 
    $ctx = stream_context_create(array('http' => array('timeout' => 120))); 
    if (!file_exists($localfilev4)) { 
     if (current_user_can('install_plugins')) { 
      echo 
      '<div class="notice notice-warning is-dismissible"><p>Notice: This plugin uses Maxmind Geolite databases for better accuracy. Click the download button to install now. 
      <form action="" method="get"> 
      <input type="submit" class="button" name="download" value="download" /> 
      </div>'; 
      if($_GET){ 
       if(isset($_GET['download'])){ 
        $newfilev4 = file_get_contents("https://sourceforge.net/projects/geoipupdate/files/GeoIPv4.dat/download", 0, $ctx); 
        file_put_contents($dir . '/data/GeoIPv4.dat', $newfilev4); 
        if (!file_exists($localfilev6)) { 
         $newfilev6 = file_get_contents("https://sourceforge.net/projects/geoipupdate/files/GeoIPv6.dat/download", 0, $ctx); 
         file_put_contents($dir . '/data/GeoIPv6.dat', $newfilev6); 
        } 
       } 
       echo '<meta http-equiv="refresh" content="0">'; 
      } 
     } 
    } 
} 
+0

试试这个http://stackoverflow.com/a/42235569/2282880 – Meloman

回答

2

试着给你的按钮的ID如下:

<input type="submit" class="button" name="download" value="download" id="download" /> 

也给你的div就像一个id这样:

<div class="notice notice-warning is-dismissible" id="download-div"> 

然后我们可以使用一个基本的jQuery的onClick功能和变化像这样的innerhtml:

$("#download").click(
     function() { 
      $('#download-div').html("Please wait..."); 
     }    
    ); 
}); 

希望这有助于:)

+0

工作就像一个魅力。唯一的变化是添加'jQuery(document).ready(function($){'到顶部。谢谢! – j8d

+1

没问题,我忘了 – iJamesPHP

相关问题