简体   繁体   English

如何检查JavaScript是否在Node JS服务器端代码中启用

[英]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.

相关问题 使用node.js时如何在客户端和服务器端导入javascript代码? - How to import javascript code both on the client and on the server side when using node.js? 检查Javascript是否已启用服务器端ASP.NET - Check if Javascript is enabled server side ASP.NET 如何在服务器端(Node.js)上使用javascript生成HTML? - How to generate HTML with javascript on the server side (Node.js)? 如何使javascript库在节点js中工作以进行服务器端操作 - how to make a javascript library working in node js for server side operations 如何从 javascript 调用 node.js 服务器端方法? - How to call node.js server side method from javascript? 获取客户端javascript代码中可用的node.js服务器端对象 - Get node.js server-side object available in client-side javascript code 检测在服务器端启用的 Javascript - Detect Javascript enabled on server side Node.js如何检查服务器应用程序中是否有某些代码被阻止 - Node.js how to check if some code is blocking in a server application 如何检查js代码是在节点服务器上还是在客户端上运行 - How to check if js code is running on node server or on the client 如何使用来自 javascript(客户端)的变量从 node.js(服务器端)检索数据? - How to retrieve data from node.js (server side) using a variable from javascript (client side)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM