Setting window.name in JavaScript to use later from another page?
P粉821808309
P粉821808309 2023-09-16 23:44:59
0
1
547

In a window, such as foo.example.com:

Then in another window, later, for example bar.example.com:

GOFOO

Will this work? Is there a way to return to a window that was not originally named withtarget=''?

P粉821808309
P粉821808309

reply all (1)
P粉434996845

The name attribute of the window can indeed be set in JavaScript. However, it doesn't work exactly the way you imagine.

In HTML, the target attribute of theelement is used to specify where to open the linked document. The value of this attribute can be:

_blank: Open the linked document in a new window or tab._self: Open the linked document in the same frame as when clicked (this is the default)._parent: Open the linked document in the parent frame._top: Open the linked document in the entire body of the window. framename: Open the linked document in the named frame. Therefore, the value of the target attribute is interpreted as the frame name, not window.name. They are not directly related.

However, window.name plays a certain role in cross-window communication. When you navigate from one page to another, window.name remains the same (even when navigating across domains) until the window or tab is closed, or the window or tab navigates to a different domain where window.name is cleared page. But it won't work the way you're trying to use it in your example.

It should be noted that the window.name attribute is mainly used for script programming, not as a way to reference windows between pages through thetag.

What you are trying to achieve - referencing an existing window/tab from another window/tab - is often not directly possible due to limitations of the Same Origin Policy and restrictions on inter-window communication for security reasons.

However, you can use other methods, such as using localStorage, sessionStorage, or postMessage to achieve some form of inter-window or inter-tab communication, depending on your needs.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!