我想在 javascript 条件内使用 PHP 发送 header 。这可能吗?
if ($('body').hasClass('browserChrome')) {
<?php
header("Content-Type: application/x-chrome-extension");
header('Content-Disposition: attachment; filename="http://example.com/file.crx"');
header("Pragma: no-cache");
header("Expires: 0");
?>
}
最佳答案
那是行不通的。首先,您的 Web 服务器将执行 PHP 脚本,从而生成带有 JavaScript 的 HTML 页面。然后将其发送到用户的 Web 客户端,该客户端将显示 HTML 并执行 JavaScript。当 JavaScript 解释器到达 PHP 代码时,没有任何痕迹。
关于JavaScript 条件中的 PHP header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5022701/