Why is window.name cached?

后端 未结 2 1437
走了就别回头了
走了就别回头了 2020-12-10 07:31

in a programming challenge I recently took part in I had to use the window.name property to store / manipulate data. I found out that, when you change this prop

相关标签:
2条回答
  • 2020-12-10 07:44

    Named windows are used as link targets, for one:

    <a href="example.html" target="some_page">some page</a>
    

    The link will open in a new window once, and in the same window if it still exists on subsequent clicks, with the window’s name being how it’s targeted.

    The second argument of window.open is also a window name.

    window.open('example.html', 'some_page');
    

    You can try it out in your browser across unrelated websites; in one tab’s console, set window.name = 'test'; and in the other, use window.open('https://example.com/', 'test');. (You may have to let it through a pop-up blocker.) The unrelated tab should navigate to https://example.com/.

    0 讨论(0)
  • 2020-12-10 07:51

    My understanding of it is that the window object is persistent throughout the lifetime of a tab, and represents the window that is loading different HTML documents.

    Each tab contains its own window object, which is why even when you navigate to/from different pages the window object is persistent, whereas if you check on a different tab the window.name will be different.

    When opening different html pages, most of them do not override the window.name property, and it is completely optional. If nothing else is manipulating it, it will be what you leave it as. Most pages only touch on manipulating the window.document itself.

    0 讨论(0)
提交回复
热议问题