search

Home  >  Q&A  >  body text

在node.js里面可以使用window对象的方法吗

比如说window.location.href之类

巴扎黑巴扎黑2787 days ago338

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 16:15:57

    window是浏览器的规范,并非js语言规范,所以在nodejs当然不能用。
    不过nodejs有个类似的全局变量,叫golgal,当然了,它内部的内容和浏览器中的windowIt’s just very different.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 16:15:57

    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

    reply
    0
  • PHPz

    PHPz2017-04-17 16:15:57

    Definitely not possible, the location belongs to the BOM, right, only the client has it...

    reply
    0
  • Cancelreply