Window

Browsers typically don"t allow a child tab/window lớn cthua thảm its opener with script. And yet they vày allow the child to lớn alter the location of the opener tab/window.

Bạn đang xem: Window

This leads lớn a curious workaround whereby you can create a page that does nothing but cthua itself with script as soon as its loaded, & then change the location of the parent tab/window to lớn this new page, effectively closing it.

Which leads me khổng lồ ask, what phukienotocaocap.com issue lead to lớn disabling the ability khổng lồ cthảm bại an opener tab/window, và does this workaround effectively create a baông chồng door?


web-browser javascript
Share
Improve this question
Follow
edited May 23 "17 at 12:40
*

Community♦
1
asked Aug 12 "16 at 13:53
*

AntonChanningAntonChanning
18311 gold badge11 silver badge77 bronze badges
1
Add a bình luận |

1 Answer 1


Active sầu Oldest Votes
3
Browsers typically don"t allow a child tab/window khổng lồ cthất bại its opener with script. And yet they vày allow the child lớn alter the location of the opener tab/window.

This is not entirely accurate. If you read the quoted MDN text more carefully, it is actually referring khổng lồ the opening of the parent, not the relationship to lớn its popup. The actual restriction you are probably running inkhổng lồ is:

Scripts may only cthảm bại windows were originally opened by script.

So in your specific example, the popup was opened by a script, but the opener was opened by a user, and therefore the opener cannot be closed by either itself or the popup.

Xem thêm: Linux Mint - Và 5 Lý Do Tại Sao Nó Tốt Hơn Ubuntu

Imagine a scenario where there are two popups

User-opened tab (cannot be closed)Popup 1 (opener is user-opened tab)Popup 2 (opener is popup 1)

Popup 2 can cđại bại popup 1 in this scenario.However, popup 1 cannot cthua kém the user-opened tab because that violates the rule above sầu.

In Chrome & Firefox, it does not matter whether the popups are same origin as their openers. The popup can change the location or cthua thảm the opener as desired, subject khổng lồ my first point above sầu.

Also, I"d like lớn clarify that any opener can cchiến bại its own popups or change their location without restriction. Access to lớn the popup contents is still subject lớn Same Origin policy for phukienotocaocap.com reasons.

Xem thêm: Used To Là Gì - Cấu Trúc Used To Và Cách Sử Dụng Phổ Biến

This leads to lớn a curious workaround whereby you can create a page that does nothing but close itself with script as soon as its loaded, & then change the location of the parent tab/window khổng lồ this new page, effectively closing it. ... does this workaround effectively create a baông chồng door?

To answer your question directly, there is no such workaround. The linked example will produce the error:

Scripts may not cchiến bại windows that were not opened by script.

Unless you are in a 2-popup situation as I explained above sầu, in which case the popup could just cchiến bại its opener directly. The workaround would be unnecessary in that case though.


Chuyên mục: Blogs