[英]How to check javascript is enabled or not in Node JS server side code
Is this possible to check this using server side code in Node js? 是否可以使用Node js中的服务器端代码进行检查? OR if not then how can I use conditions like if-else: 否则,如何使用if-else这样的条件:
if enabled then
do this
else
do that
In a node.js
project, I have to check that JavaScript
is enabled or not on browser of user. 在node.js
项目中,我必须检查用户浏览器上是否启用了JavaScript
。
I know that we can check this using <noscript>
tag at client side code(I am using jade). 我知道我们可以在客户端代码中使用<noscript>
标记检查此情况(我使用的是玉)。 On Jade page I have inserted <noscript>
tag which displays message that JavaScript
is disabled. 在Jade页面上,我插入了<noscript>
标记,该标记显示禁用JavaScript
消息。 eg 例如
noscript
.noscriptmsg(style="color:red; padding:15px;")
| You don't have javascript enabled on your Browser. Please enable to use complete functionality.
| To know more
a(href='http://enable-javascript.com/')
| Click Here
this is good to display the error message to user. 向用户显示错误消息是很好的。
But I wants to know it on my server side code in node.js
. 但是我想在node.js
服务器端代码中知道它。 I am using express
framework. 我正在使用express
框架。
I wants to make case for each and every page if JavaScript
is disabled then user cannot move further OR in running app if user will disable JavaScript
then app will be redirected on JS-No Found page. 我想在每个页面上都设置大小写(如果禁用了JavaScript
),那么用户将无法进一步移动;或者,如果用户将禁用JavaScript
则无法在运行的应用程序中移动,则应用程序将在JS-No Found页面上重定向。
OR some kind of conditional part in <noscript>
part. 或<noscript>
部分中的某种条件部分。
Can anyone please guide me how can I detect JS enable or disable on server side in Node.JS. 谁能指导我如何在Node.JS的服务器端检测JS启用或禁用。
You can put a <meta>
tag in a <noscript>
block to redirect to some special URL: 您可以将<meta>
标记放在<noscript>
块中,以重定向到某些特殊的URL:
<noscript>
<meta http-equiv=refresh content='0; url=http://your.domain/noscript'>
</noscript>
You cannot of course be 100% certain that users who land on the special URL are there because they've disabled JavaScript, but for people not doing anything weird (other than disabling JavaScript) it works. 您当然不能百分百确定使用特殊URL的用户是否在那儿,因为他们已经禁用了JavaScript,但是对于那些没有做任何奇怪事情(除了禁用JavaScript)的人来说,它是可行的。
You can expose a GET / POST endpoint on your express app - ex: /jsenabled/ 您可以在快递应用程序上公开GET / POST端点-例如: / jsenabled /
In the html page - On document ready you can call '/jsenabled' 在html页面中-准备好文档后,您可以调用'/ jsenabled'
In the jsenabled express handler -infer the user from the session / cookies 在jsenabled快递处理程序中-从会话/ Cookie推断用户
By default assume user has no js until you get this call 默认情况下,假设您没有js,直到您收到此调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.