How to communicate between multiple windows of the same chrome app?

前端 未结 2 941
别跟我提以往
别跟我提以往 2020-12-16 05:58

When using chrome developer tools, it appears that each app window (and the background \'page\') has its own javascript context (space of objects, thread of execution), and

2条回答
  •  感情败类
    2020-12-16 06:35

    That is a great question James!

    Multiple chrome windows are not completely separate. They share a single thread and object space, however the window object is different for each. In javascript unscoped references to things are looked up on the current window, so this makes the windows appear to be different object spaces - but they are not really.

    So, you can reach into another window and execute a function there, or manipulate state in other ways (e.g. set a variable on another window to a function from the current window) and it is acceptable and supported.

提交回复
热议问题