- Window.name
- Value
- Description
- Examples
- Specifications
- Browser compatibility
- Нашли проблему на этой странице?
- Window: name property
- Value
- Description
- Examples
- Specifications
- Browser compatibility
- Found a content problem with this page?
- Open Link in New Window
- Named Windows
- Frames
- : The Anchor element
- Try it
- Attributes
- Deprecated attributes
Window.name
Свойство Window.name получает / устанавливает имя контекста просмотра окна.
Value
Description
Имя окна используется в основном для задания целей для гиперссылок и форм.Контексты просмотра не обязательно должны иметь имена.
Современные браузеры сбрасывают Window.name на пустую строку, если вкладка загружает страницу из другого домена, и восстанавливают имя, если исходная страница перезагружается (например, путем нажатия кнопки «назад»). Это предотвращает доступ ненадежной страницы к любой информации, которая могла быть сохранена на предыдущей странице в свойстве (потенциально новая страница может также изменять такие данные, которые затем могут быть прочитаны исходной страницей, если она была перезагружена).
Window.name также используется в некоторых фреймворках для междоменного обмена сообщениями (например, dojox.io.windowName в Dojo ) как более безопасная альтернатива JSONP. Однако современные веб-приложения, размещающие конфиденциальные данные, не должны полагаться на window.name для обмена сообщениями между доменами — это не является его предполагаемой целью, и существуют более безопасные и лучшие способы обмена информацией между окнами. Window.postMessage() — рекомендуемый механизм.
Примечание. window.name преобразует все сохраненные значения в их строковые представления с помощью метода toString .
Examples
script> // Открываем вкладку с определенным именем контекста просмотра const otherTab = window.open("url1", "_blank"); if (otherTab) otherTab.name = "other-tab"; script> a href="url2" target="other-tab">This link will be opened in the other tab. a>
Specifications
Browser compatibility
До Firefox 86, если новая страница из другого домена загружается во вкладку, тогда window.name не устанавливается в пустую строку, что может допускать некоторые межсайтовые атаки. См. Ошибку 1685089 и ошибку 444222 .
До Firefox 86, если новая страница из другого домена загружается во вкладку, тогда window.name не устанавливается в пустую строку, что может допускать некоторые межсайтовые атаки. См. Ошибку 1685089 и ошибку 444222 .
Нашли проблему на этой странице?
Last modified: Apr 6, 2022 , авторы MDN
Web APIs
Свойство mozInnerScreenY интерфейса Window возвращает координаты верхнего левого угла окна просмотра, координаты.
Свойство Window.navigator,доступное только для чтения,возвращает объект ссылки,который имеет методы и свойства о запущенном скрипте приложения.
Событие Offline интерфейса Window срабатывает,когда браузер потерял доступ к сети и значение Navigator.onLine переключается на false.
Window: name property
The Window.name property gets/sets the name of the window’s browsing context.
Value
Description
The name of the window is used primarily for setting targets for hyperlinks and forms. Browsing contexts do not need to have names.
Modern browsers will reset Window.name to an empty string if a tab loads a page from a different domain, and restore the name if the original page is reloaded (e.g. by selecting the «back» button). This prevents an untrusted page from accessing any information that the previous page might have stored in the property (potentially the new page might also modify such data, which might then be read by the original page if it was reloaded).
Window.name has also been used in some frameworks for providing cross-domain messaging as a more secure alternative to JSONP. Modern web applications hosting sensitive data should, however, not rely on window.name for cross-domain messaging — that is not its intended purpose and there are safer/better ways of sharing information between windows. Window.postMessage() is the recommended mechanism.
Note: window.name converts all stored values to their string representations using the toString method.
Examples
script> // Open a tab with a specific browsing context name const otherTab = window.open("url1", "_blank"); if (otherTab) otherTab.name = "other-tab"; script> a href="url2" target="other-tab">This link will be opened in the other tab.a>
Specifications
Browser compatibility
BCD tables only load in the browser
Found a content problem with this page?
This page was last modified on Apr 8, 2023 by MDN contributors.
Your blueprint for a better internet.
Open Link in New Window
This page explains and demonstrates how to create a link that opens in a new browser window. The quickest way to open a link in a new window is to add target=»_blank» to your tag (which of course, is the HTML tag to create a link).
Named Windows
You can take this a step further and create a name for the new window. This can be useful in case you want to open more than one link in the same window (instead of opening a new window for each link). In other words, when a user clicks on the first link, it will open a new window. Then, each time the user clicks on a different link, the new link will load into that same window.
Probably easier to show you an example.
Try clicking on the first link below, then go back and click on the second link. You’ll see that, when you click on the second link, it loads into the same window that the first link loaded into.
Database (Link opens in the same window that the previous link loaded into)
As you can see, I created a name for the new window called «external». I only called it this to give it some sort of meaning (i.e. «external» for external links). I could have called it anything — say «Bob», «Mary», or even «Harold».
You don’t have to stop at one named window, you could create two or more. Having said this, try to remember your users. As a website visitor, it can be annoying if too many different windows are opening up.
Frames
Named windows are perfect for loading a link into a frame. For example, if you have an iframe, you could open the contents of a link into the iframe and the link doesn’t need to be within the iframe itself.
: The Anchor element
The HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.
Try it
Attributes
This element’s attributes include the global attributes.
Causes the browser to treat the linked URL as a download. Can be used with or without a filename value:
- Without a value, the browser will suggest a filename/extension, generated from various sources:
- The Content-Disposition HTTP header
- The final segment in the URL path
- The media type (from the Content-Type header, the start of a data: URL, or Blob.type for a blob: URL)
- download only works for same-origin URLs, or the blob: and data: schemes.
- How browsers treat downloads varies by browser, user settings, and other factors. The user may be prompted before a download starts, or the file may be saved automatically, or it may open automatically, either in an external application or in the browser itself.
- If the Content-Disposition header has different information from the download attribute, resulting behavior may differ:
- If the header specifies a filename , it takes priority over a filename specified in the download attribute.
- If the header specifies a disposition of inline , Chrome and Firefox prioritize the attribute and treat it as a download. Old Firefox versions (before 82) prioritize the header and will display the content inline.
The URL that the hyperlink points to. Links are not restricted to HTTP-based URLs — they can use any URL scheme supported by browsers:
- Sections of a page with document fragments
- Specific text portions with text fragments
- Pieces of media files with media fragments
- Telephone numbers with tel: URLs
- Email addresses with mailto: URLs
- While web browsers may not support other URL schemes, websites can with registerProtocolHandler()
Hints at the human language of the linked URL. No built-in functionality. Allowed values are the same as the global lang attribute.
A space-separated list of URLs. When the link is followed, the browser will send POST requests with the body PING to the URLs. Typically for tracking.
How much of the referrer to send when following the link.
- no-referrer : The Referer header will not be sent.
- no-referrer-when-downgrade : The Referer header will not be sent to origins without TLS (HTTPS).
- origin : The sent referrer will be limited to the origin of the referring page: its scheme, host, and port.
- origin-when-cross-origin : The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.
- same-origin : A referrer will be sent for same origin, but cross-origin requests will contain no referrer information.
- strict-origin : Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don’t send it to a less secure destination (HTTPS→HTTP).
- strict-origin-when-cross-origin (default): Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP).
- unsafe-url : The referrer will include the origin and the path (but not the fragment, password, or username). This value is unsafe, because it leaks origins and paths from TLS-protected resources to insecure origins.
The relationship of the linked URL as space-separated link types.
Where to display the linked URL, as the name for a browsing context (a tab, window, or ). The following keywords have special meanings for where to load the URL:
- _self : the current browsing context. (Default)
- _blank : usually a new tab, but users can configure browsers to open a new window instead.
- _parent : the parent browsing context of the current one. If no parent, behaves as _self .
- _top : the topmost browsing context (the «highest» context that’s an ancestor of the current one). If no ancestors, behaves as _self .
Note: Setting target=»_blank» on elements implicitly provides the same rel behavior as setting rel=»noopener» which does not set window.opener .
Hints at the linked URL’s format with a MIME type. No built-in functionality.
Deprecated attributes
Hinted at the character encoding of the linked URL.
Note: This attribute is deprecated and should not be used by authors. Use the HTTP Content-Type header on the linked URL.
Used with the shape attribute. A comma-separated list of coordinates.
Was required to define a possible target location in a page. In HTML 4.01, id and name could both be used on , as long as they had identical values.
Note: Use the global attribute id instead.
Specified a reverse link; the opposite of the rel attribute. Deprecated for being very confusing.
The shape of the hyperlink’s region in an image map.