闪存不会嵌入到 ie9 中

Flash won't embed in ie9

本文关键字:ie9 闪存      更新时间:2023-09-26

>编辑:这是我试图在IE9中开始使用的github示例代码,你有你需要的一切,我已经展示了我尝试过的例子,所以为什么要投票给我?

我正在使用这个简单的 github 示例代码将一些数据保存在动态创建的弹出窗口中。闪存绕过了保存的安全限制,在Chrome和FireFox中运行良好。

在IE9(可能所有IE)中,浏览器要求保存swfobject.js然后失败。它不是跨站点的,也不是本地的,而是在常规的 apache 服务器上。

https://github.com/gitbuh/bhd

代码位于示例文件夹中。

我已经尝试了一些事情,例如将其替换为最新的 swfobject.js v2.2

并使用IE友好的文档类型和元,但没有运气。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />

我相对确定问题出在进行嵌入的bhd.js,并且我已经尝试了设置,但没有运气,这是bhd.js的代码:

/** BHD
    Browser-Hosted Download
*/
function BHD () {
  return new BHD.Button(opts, callback);
}
BHD.uid = function () {
  return 'x'+(+(''+Math.random()).substring(2)).toString(32)+(+new Date()).toString(32);
};
BHD.getScriptPath = function () {
  if (this.scriptPath) return this.scriptPath;
  var scripts = document.getElementsByTagName('script');
  for (var i=scripts.length, m; i--;) {
    if ((m=(''+scripts[i].src).match(/(.*'/?)bhd.js('?|$)/))) {
      return this.scriptPath = m[1] || '';
    }
  }
  return this.scriptPath = '';
}
BHD.include = function (file, callback) {
  var uid = BHD.uid(), frame;
  frame = document.createElement('iframe');
  frame.src = file;
  frame.id = frame.name = uid;
  frame.onload = function () {
    var s = document.getElementsByTagName('script')[0]; 
    var d = frames[uid].document.documentElement;
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.text = d.textContent||d.innerText;
    s.parentNode.insertBefore(script, s);
    callback();
    s.parentNode.removeChild(s);
    frame.parentNode.removeChild(frame);
  }
  document.documentElement.appendChild(frame);
}
/** BHD.Button
*/
BHD.Button = function (opts, callback) {
  this.opts = opts;
  if (!opts) return;
  this.setup(opts, callback);
}

/** setup
    Embed the SWF object.
    @param String opts
*/
BHD.Button.prototype.setup = function (opts, callback) {
  var button = this;
  var flashvars = opts;
  var params = { 
    quality: 'high', 
    wmode: 'transparent', 
    swLiveConnect: 'true',
    menu: 'false',
    scale: 'noScale',
    allowFullscreen: 'true',
    allowScriptAccess: 'always'
  };
  var attributes = { id: opts.id, name: opts.id };
  this.opts = opts;
  opts.callbackName = BHD.uid();
  window[opts.callbackName] = callback;
  window[opts.callbackName + '_resize'] = function(w, h){
    object = button.getElement();
    object.style.width = w + 'px';
    object.style.height = h + 'px';
  };
  var cb = function(){
    swfobject.embedSWF(BHD.getScriptPath() + 'bhd.swf', 
        opts.id, '1', '1', '9.0.0', 
        null, flashvars, params, attributes);
  }
  if (typeof swfobject == 'undefined') {
    BHD.include(BHD.getScriptPath() + 'swfobject.js', cb);
  } else {
    cb();
  }
};

/** getElement
    Get the embedded flash element, or element to be replaced
    if swfobject.embedSWF has not finished yet.
    @param String variable
    @param Mixed value 
*/
BHD.Button.prototype.getElement = function () {
  return document.getElementById(this.opts.id);
};
/** setFile
    Set the default filename to show in the save dialog.
    @param String value 
*/
BHD.Button.prototype.setFile = function (value) {
  return this.getElement().setFile(value);
};
/** setData
    Set the contents of the download file.
    @param Mixed value 
*/
BHD.Button.prototype.setData = function (value) {
  return this.getElement().setData(value);
};
/** setUrl
    Set the URL of the download file.
    @param Mixed value 
*/
BHD.Button.prototype.setUrl = function (value) {
  return this.getElement().setUrl(value);
};

看起来bhd.js脚本在IE9中无法正确引导swfobject.js。将此行添加到第 4 行上方example/index.html,可修复 IE9 的问题。

<script src="../dist/swfobject.js"></script> 

在IE 10中确认了相同的问题,此修复程序也有效。