我可以让PHP知道用户没有启用javascript吗? [英] Can I let PHP know that a user does not have javascript enabled?

查看:65
本文介绍了我可以让PHP知道用户没有启用javascript吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以让PHP知道用户没有启用javascript吗?

Can I let PHP know that a user does not have javascript enabled?

推荐答案

首先假设javascript已关闭可用,然后向客户端发送一些HTML,其中包含此

Start by assuming javascript is off or not available, then send the client some HTML which includes this

<script>
window.location = "http://www.mysite.com/javascript.php?enabled=true";
</script>
<noscript>
possible tell the user the consequences of not having javascript enabled

</noscript>

在javascript.php脚本中,您可以存储客户端支持javascript的会话。您也可以使用XMLHTTPRequest对象而不是直接重定向。

In the javascript.php script, you can store in the session that the client supports javascript. You could also do with with an XMLHTTPRequest object rather than a straight redirect.

但是,根据您的应用程序,构建应用程序以便在没有Javascript的情况下工作几乎总是更好,可能效率较低,然后让您的脚本启动并使用增强功能扩充基本版本。这样,您就不需要检测它,只要它可用就可以使用它。

However, depending on your application, it's almost always better to build your app to work without Javascript, perhaps less efficiently, and then have your script kick in and augment the basic version with enhanced functionality. That way, you don't need to detect it, you just use it if its available.

这篇关于我可以让PHP知道用户没有启用javascript吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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