【发布时间】:2017-06-09 00:42:55
【问题描述】:
我正在尝试打开一个新选项卡以在单击 txt 文件时显示它的内容。它适用于 Chrome 和 IE(一次),但不适用于 Firefox。
所以基本上我在<a></a> 文件中的<a></a> 标签中添加了target="_blank":
<a class="log" onClick="event.stopPropagation()" style="float:Right;" href="http://localhost/report/Java/16/9/log/buildLog20170124090806.txt" target="_blank">File</a>
在 Chrome 和 IE 上,它会在新标签页中打开,但 在 Firefox 中,它会下载文件。响应 HTTP 标头是:
Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Tue, 24 Jan 2017 09:48:51 GMT
Keep-Alive: timeout=5, max=79
Server: Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28
Set-Cookie: XSRF-TOKEN=DRiYzQxODY5ZGNhZDBiYmI3YmE0Y2UzMzQzZWVmMWViNSJ9; expires=Tue, 24-Jan-2017 11:48:52 GMT; Max-Age=7200; path=/Max-Age=7200; path=/; httponly
X-Powered-By: PHP/5.6.28
如何强制 Firefox 在新标签页中打开它?
我对同一页面中的 HTML 文件使用了相同的语法,并且效果很好。
【问题讨论】:
-
你发送什么 HTTP 标头?
-
标题是什么意思?
<head></head>标签中有什么?对不起,我是这个 HTML 世界的新手,我正在处理别人的代码...... -
在 Firefox 中,按 Ctrl+Shift+Q。将打开一个新面板。当您加载链接时,将显示一个新条目。单击它时,您将看到一个包含“响应标头”块的新子窗格。这些是 Web 服务器发回的 HTTP 标头,其中可以包含有关如何处理文件的信息。
-
这里:
Cache-Control: no-cache Connection: Keep-Alive Content-Length: 0 Content-Type: text/html; charset=UTF-8 Date: Tue, 24 Jan 2017 09:48:51 GMT Keep-Alive: timeout=5, max=79 Server: Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28 Set-Cookie: XSRF-TOKEN=DRiYzQxODY5ZGNhZDBiYmI3YmE0Y2UzMzQzZWVmMWViNSJ9; expires=Tue, 24-Jan-2017 11:48:52 GMT; Max-Age=7200; path=/Max-Age=7200; path=/; httponly X-Powered-By: PHP/5.6.28 -
Content-Length: 0?文件应该是空的吗?
标签: javascript php html firefox cross-browser