Firefox在另存为类型-另存为对话框中的文件类型不正确

Firefox incorrect file type in Save as type - Save as dialog

本文关键字:类型 另存为 文件 不正确 Firefox 对话框      更新时间:2023-09-26

我正在尝试使用filesver .js (https://github.com/eligrey/FileSaver.js/)

当我保存jpg类型的图像时,在Firefox中显示的另存为对话框在另存为类型下拉菜单中给出了不正确的值(它说"PNG图像(.jpg),但我期望的是JPEG图像(.jpg))。

谁能告诉我如何解决这个问题?

最后,我找到了这个问题的原因。

我使用canvas-toblob javascript库将画布转换为blob。但是Firefox有toblob方法的内部实现,所以canvas-toblob.js中的相同方法永远不会被调用。

我修改了canvas-toblob.js,以便Firefox将使用这个库中的方法。这就解决了我的问题

if (HTMLCanvasElement) { canvas_proto.toBlob = function(callback, type /*, ...args*/) { if (!type) { type = "image/png"; } if (this.msToBlob && /^'s*image'/png's*(?:$|;)/i.test(type)) { callback(this.msToBlob()); return; }

您需要为类型参数指定image/jpeg