比如说window.location.href之类
window是浏览器的规范,并非js语言规范,所以在nodejs当然不能用。 不过nodejs有个类似的全局变量,叫golgal,当然了,它内部的内容和浏览器中的windowIt’s just very different.
window
nodejs
golgal
Why do we need to get window in node?
If you need to execute it, you can write it into html when rendering, but it is strongly not recommended!!
<!-- html --> <script> window.localStorage.test = '123' </script>
The best way is to use client logic + interface
Definitely not possible, the location belongs to the BOM, right, only the client has it...
window
是浏览器的规范,并非js语言规范,所以在nodejs
当然不能用。不过
nodejs
有个类似的全局变量,叫golgal
,当然了,它内部的内容和浏览器中的window
It’s just very different.Why do we need to get window in node?
If you need to execute it, you can write it into html when rendering,
but it is strongly not recommended!!
The best way is to use client logic + interface
Definitely not possible, the location belongs to the BOM, right, only the client has it...