這適用於未安裝Flash和安裝Flash但已禁用。我只在IE7-9和FF19中確認過它,但應該可以在任何可以使用Uploadify SWF版本的瀏覽器中使用。
在html中有2個div。一個沒有Flash和與Flash
<div id="uploadifyDiv" runat="server" style="float: left; width: 100%; margin-top: 10px;">
<div id="uploadifyNoFlashDiv">
<p style="font-weight:bold; background-color:Red; color:Black;">Flash is not installed or is not enabled</p>
File upload requires Flash to be installed and enabled.<br />
Click <a href="http://get2.adobe.com/flashplayer/" target="_blank">here</a> to install<br />
You will need to <a href="javascript:window.location.href=window.location.href">refresh</a> the page when installation is completed</p>
</div>
<div id="uploadifyHasFlashDiv" style="display:none;">
<asp:FileUpload ID="ImageFileUpload" runat="server" />
</div>
</div>
在Uploadify腳本包括OnInit的
onInit : function(instance) {
$('[id$="uploadifyNoFlashDiv"]').css('display','none');
$('[id$="uploadifyHasFlashDiv"]').css('display','block');},
如果沒有安裝Flash或已安裝但尚未啓用的功能,那麼uploadifyNoFlashDiv DIV將顯示,否則OnInit將隱藏uploadifyNoFlashDiv div並顯示uploadifyHasFlashDiv div,假設其他一切正常,將渲染Uploadify控件。
這當然不提供任何功能,如果用戶沒有安裝Flash,但它至少
- 顯示相應的消息通知他們需要安裝Flash(或啓用它,如果已經安裝)
- 隱藏如果Uploadify腳本失敗,則會出現通用的FileUpload
恕我直言,Uploadify仍然優於其他上傳者作爲替代品,因爲它是唯一一個在非HTML5瀏覽器中提供多個文件選擇,可悲的是包括IE9在Win7上。所有其他上傳者只允許在文件對話框中選擇單個文件。
編輯:在慢速連接上,在Uploadify腳本有機會運行時,如果他們確實安裝了Flash並且div最終會隱藏,則會顯示No Flash已安裝的div。在這種情況下,添加另一個div,並在其中加載gif,然後在文檔加載上運行一些腳本以顯示相應的div。
<div id="uploadifyDiv" runat="server" style="float: left; width: 100%; margin-top: 10px;">
<div id="uploadifyNoFlashDiv" runat="server" class="infoBoxDiv" style="display: block;">
<div id="uploadifyNoFlashLoadingDiv" style="display:block">
<img src="../images/uploading.gif" alt="Loading ..." /> Loading. Please wait a moment ...
</div>
<div id="uploadifyNoFlashFinalDiv" style="display:none;">
<p style="font-weight: bold; background-color: Red; color: Black;">
Flash is not installed or is not enabled</p>
<p>
File upload requires Flash to be installed and enabled.<br />
Click <a href="http://get2.adobe.com/flashplayer/" target="_blank">here</a> to install<br />
You will need to <a href="javascript:window.location.href=window.location.href">refresh</a>
the page when installation is completed
</p>
</div>
</div>
<div id="uploadifyHasFlashDiv" runat="server" style="display: none;">
<asp:FileUpload ID="ImageFileUpload" runat="server" />
</div>
</div>
<script language="javascript" type="text/javascript">
// If the NoFlashDiv is still visible then hide the loading gif and show the info box
// Otherwise leave alone and the Uploadify script will do its thing
$(document).ready(function() {
if ($('[id$="uploadifyNoFlashDiv"]').css('display') == 'block')
{
$('[id$="uploadifyNoFlashLoadingDiv"]').css('display','none');
$('[id$="uploadifyNoFlashFinalDiv"]').css('display','block');
}
});
</script>
有趣的問題。 「優雅的降級」不在Uploadify的功能列表上,儘管可能沒有辦法做到這一點(除了檢查Flash本身並顯示正常輸入) – 2011-02-28 00:26:42
更新此問題: 截至2012年春季,現在有一個商業HTML5 Uploadify的版本:Uploadifive。 我正在加載uploadifive in body onload()並隱藏Flash版本,如果上傳按鈕中的文本沒有改變,我設置style:「display:none;」到HTML5版本並切換到Flash版本。 – 2012-06-15 03:13:50
然後再次這將是在沒有HTML5支持IE瀏覽器上的問題... – zaw 2013-05-07 02:55:38