您可以在Firefox中更改MIME嗅探设置来解决此问题。以下是一个示例代码,您可以使用它将Firefox的MIME嗅探设置更改为仅允许特定扩展名:
user_pref("browser.download.extensions_to_open", "jpg,jpeg,png,gif,pdf,doc,docx,xls,xlsx,ppt,pptx,txt");
user_pref("browser.download.mimeTypes.override_more", "application/pdf;pdf,application/vnd.ms-excel;xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;xlsx,application/msword;doc,application/vnd.openxmlformats-officedocument.wordprocessingml.document;docx,application/vnd.ms-powerpoint;ppt,application/vnd.openxmlformats-officedocument.presentationml.presentation;pptx,text/plain;txt,image/jpeg;jpg,image/jpeg;jpeg,image/png;png,image/gif;gif");
使用上面给出的代码,将扩展名限制为只有“jpg,jpeg,png,gif,pdf,doc,docx,xls,xlsx,ppt,pptx,txt”。如果您需要添加更多的扩展名,请在顺序中使用逗号分隔它们。此代码段还将覆盖默认MIME类型并为每个扩展名设置适当的类型。