且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-12-05 14:04:52

首先假设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.