In Internet Explorer, a tab/window will be closed silently if it was created as a result of a JavaScript window.open() call. Unfortunately for us, each browser has a different set of behaviors ( explore with this test page), partly because most were implemented before the standard was written. (Most obviously, “what should we do if the script was run in response to an action of the user?“) What Do Browsers Do? This seems simple enough, although the parts I’ve bolded hide a lot of complexity and nuance. Here’s what the dom-window-close section of the HTML Standard has to say:Ī browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user ), or if it is a top-level browsing context whose session history contains only one Document. There’s a minor anti-abuse/security argument as well– if a browser tab could blow itself away freely, this might be useful as a part of scareware or other user-experience abuses. The user might’ve been using a tab to explore a set of search results, and if one of those results could blow away both itself and the backstack with the search results page, this would be pretty annoying. While sometimes explained away as nebulous “ Security reasons!“, the core reason is more aligned with simple user-experience- users could lose important state in their browser window or “back/forward” stack (in IE, we called this the TravelLog) if a tab or window went away unexpectedly. Why Do Browsers Limit close()?īefore we dive into what factors govern what happens when close() is called, it’s important to understand why there’s a restriction at all. Scripts may close only the windows that were opened by them. When looking at the Developer Tools console, they’ll see a message like: Sometimes, Web Developers are surprised to find that the window.close() API doesn’t always close the browser window.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |