设置/更改iFrame的MIME类型?

5

使用JavaScript动态设置iFrame的MIME类型是否可能?DIV也一样?


这听起来像是一个XY问题 - Quentin
将类型设置为与服务器发送的MIME相同并不起作用 :( 是出于什么“安全原因”?出于安全考虑,我们也应该关闭互联网吗? - user985399
2个回答

5

编号。

MIME类型取决于您加载的内容。

对于一个框架,它将是src指定的任何内容。

Div不加载外部内容,因此没有MIME类型。


0

I may have the answer you need. Although our purposes may be different.

I spent days trying to specify MIME type for iframe because I use iframe to include text data into my .htm program. If the text data extension file name is not .txt then my Web browser will save it to local disk unexpectedly instead of appearing in myIframeElement.contentDocument.lastChild.innerText. <=== problem!!

The knowledge I have finally known to resolve the problem is that: it's the Web server not the client browser to specify the iframe MIME type! I used to use python local web server oneliner python -m SimpleHTTPServer 8888or python -m http.server 8888 they both response a certain MIME type incorrectly for my data file's proprietary extension name.

My solution is simply to use another local web server. This very short solution on Github works fine for me, Local Web server by Node.js. You can look into the source code to see why it works,

response.writeHead(200);
response.write(file, "binary");
response.end();

... and modify to the MIME type you want for your cases around here.

Example to run this Node.js local web server (Windows): d:\>node.exe static_server.js
I hope this helps!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接