[Webkit-unassigned] [Bug 221547] history.length starts at 2 in a new tab opened by target="_blank"

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Feb 23 16:55:46 PST 2021


https://bugs.webkit.org/show_bug.cgi?id=221547

--- Comment #3 from potassium634iodide828 at gmail.com ---
(In reply to Chris Dumez from comment #2)
> I think this may be a side effect of Safari's "back to close tab" feature.
> In the user interface, you are also able to press the back button and it
> closes the tab.

Thank you for checking this bug.

I love the behavior of the "back to close tab" feature, but other browsers (e.g. Chrome) don't have the feature.
To implement the same behavior of the "back to close tab" feature in cross-browser environment, I write a code in my website like this:

<button id="close">Close or back</button>
<script>
const close = document.getElementById("close");
if ( history.length === 1 ) {
  close.addEventListener("click", () => { window.close(); }, false);
} else {
  close.addEventListener("click", () => { history.back(); }, false);
}
</script>

This code enables the similar behavior to Safari's "back to close tab" feature in other browsers, which don't have the feature.
But ironically, this code doesn't work as expected in the very Safari, because of Bug 221546 and Bug 221547 (this one).

Because other browsers only allows window.close(); to work when history.length===1, I had to write the code like this.
But in Safari, the else clause is executed because of Bug 221547.
Furthermore, the button doesn't close the tab correctly because of Bug 221546.

To overcome these problems, both Bug 221546 and Bug 221547 should be fixed.
Otherwise, I'll need to use browser sniffing to detect Safari, which is an ugly way.
The "back to close tab" feature is great, but it shouldn't affect history.length.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20210224/622d058c/attachment.htm>


More information about the webkit-unassigned mailing list