Description
This is a follow-up discussion of window onmove event issue.
Here, we propose to add a new option("sticky") to window.open's features to make the created window following the movement of the current window. Let's call the new created one as a sticky window.
For instance, we can use
window.open("./sub-001.html", "_blank", "left=0,top=0,width=200,height=200,sticky");
to create a sticky window, and it will follow the movement of the current window.
We also propose to add functions to manage the sticky windows:
removeAllStickyWindows()
to let current window remove all the sticky windows.addStickyFeature()
, to make itself as a sticky window to its opener, if they are not cross-origin.removeStickyFeature()
, to remove itself from its opener's sticky windows.
The "sticky" feature is only effective if the created window is with opener, and they are not cross-origin.
The connection remains if they navigate inside the same origin.
If either window navigates to a cross-origin page, this connection will be broken.
To implement, the current window's frame keeps a weak reference to the sticky window's frame, let's call it a sticky frame.
When the screen rect of the current window changes, it checks its sticky frame, and uses moveBy
to move the sticky window.
If the sticky frame is detached, as the current window's frame only keeps a weak reference, so it won't block the release of the sticky frame. Therefore, we need to check if sticky window is still attached when we try to moveBy
it.
We do not define the relative position, for we already have left
and top
, we don't want to make the situation complex. This feature focuses on following the movement of the windows.
A window could support multi sticky windows.
There are still some corner cases that need to be addressed, such as the cross-displays problem and the cross-virtual displays problem. For more details, please see the explainer.