PHP标头内部的javascript条件? [英] PHP headers inside of a javascript condition?

查看:77
本文介绍了PHP标头内部的javascript条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在javascript条件下使用PHP发送标头。这可能吗?

I'd like to send headers with PHP, inside of a javascript condition. Is that possible?

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代码的痕迹。

That won't work. First, your web server will execute the PHP script, resulting in an HTML page with JavaScript. That is then sent to the user's web client, which will display the HTML and execute the JavaScript. There is no trace of the PHP code by the time the JavaScript interpreter gets to it.

这篇关于PHP标头内部的javascript条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆