使用swfupload.js上传文件,在IE8、火狐、谷歌浏览器中显示正常,但是在IE9下不能显示上传按钮。
打开swfupload.js文件找到307行开始的如下代码:
// Private: getFlashHTML generates the object tag needed to embed the flash in to the document
SWFUpload.prototype.getFlashHTML = function (flashVersion) {
// Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
return ['<object id="',this.movieName, '" type="application/x-shockwave-flash" data="', (this.support.imageResize ?this.settings.flash_url : this.settings.flash9_url), '" width="', this.settings.button_width, '" height="',this.settings.button_height, '" class="swfupload">',
'<param name="wmode" value="',this.settings.button_window_mode, '" />',
'<param name="movie" value="', (this.support.imageResize ?this.settings.flash_url : this.settings.flash9_url), '" />',
'<param name="quality" value="high" />',
'<param name="allowScriptAccess" value="always" />',
'<param name="flashvars" value="' +this.getFlashVars() + '" />',
'</object>'].join("");
};
将其替换为:
// Private: getFlashHTML generates the object tag needed to embed the flash in to the document
SWFUpload.prototype.getFlashHTML = function (flashVersion) {
// Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
//处理IE9中不显示上传按钮的情况
var classid = "";
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject)
Sys.ie = ua.match(/msie ([\d.]+)/)[1]
if (Sys.ie && Sys.ie.substring(0, 1) =="9") {
classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
}
return ['<object', classid,' id="', this.movieName,'" type="application/x-shockwave-flash" data="', (this.support.imageResize ?this.settings.flash_url : this.settings.flash9_url), '" width="', this.settings.button_width, '" height="',this.settings.button_height, '" class="swfupload">',
'<param name="wmode" value="',this.settings.button_window_mode, '" />',
'<param name="movie" value="', (this.support.imageResize ?this.settings.flash_url : this.settings.flash9_url), '" />',
'<param name="quality" value="high" />',
'<param name="allowScriptAccess" value="always" />',
'<param name="flashvars" value="' +this.getFlashVars() + '" />',
'</object>'].join("");
};
注:以上代码在IE7、IE8、IE9、火狐(Firefox 11.0)、谷歌(Google Chrome 17.0.963.83)浏览器中测试运行正常。