如何检查JavaScript是否在Node JS服务器端代码中启用 [英] How to check javascript is enabled or not in Node JS server side code

查看:210
本文介绍了如何检查JavaScript是否在Node JS服务器端代码中启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Node js中的服务器端代码进行检查?否则,我该如何使用如if-else这样的条件:

if enabled then 
  do this
else
  do that

node.js项目中,我必须检查用户浏览器中是否启用了JavaScript.

我知道我们可以使用客户端代码(我使用的是玉)上的<noscript>标签对此进行检查.在Jade页面上,我插入了<noscript>标记,该标记显示JavaScript被禁用的消息.例如

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

这很好地向用户显示错误消息.

但是我想在node.js中的服务器端代码中知道它.我正在使用express框架.

如果要禁用JavaScript,那么我想为每一页做个案例,那么如果用户禁用JavaScript,则用户无法在运行的应用程序中进一步移动,或者如果正在运行的应用程序中,则该应用程序将在JS-No Found页面上重定向.

<noscript>部分中的某种条件部分.

任何人都可以指导我如何在Node.JS的服务器端检测JS启用或禁用.

解决方案

您可以在<noscript>块中放置<meta>标记,以重定向到某些特殊的URL:

<noscript>
  <meta http-equiv=refresh content='0; url=http://your.domain/noscript'>
</noscript>

您当然不能100%确信使用特殊URL的用户在那儿是因为他们禁用了JavaScript,但是对于那些没有做任何奇怪的事情(除了禁用JavaScript)的人来说,它起作用了.

Is this possible to check this using server side code in Node js? OR if not then how can I use conditions like 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.

I know that we can check this using <noscript> tag at client side code(I am using jade). On Jade page I have inserted <noscript> tag which displays message that JavaScript is disabled. e.g.

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. I am using express framework.

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.

OR some kind of conditional part in <noscript> part.

Can anyone please guide me how can I detect JS enable or disable on server side in Node.JS.

解决方案

You can put a <meta> tag in a <noscript> block to redirect to some special 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.

这篇关于如何检查JavaScript是否在Node JS服务器端代码中启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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