[英]Show a “Please Wait” Message or a Progress Bar while Files Download
我使用以下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">';
}
}
}
}
嘗試給您的按鈕一個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...");
}
);
});
希望這會有所幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.