Closed Bug 1060349 Opened 10 years ago Closed 10 years ago

bug in JS and onbeforeunload that allow the website to prevent the closure of the tab from the user

Categories

(Firefox :: Untriaged, defect)

31 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1046022

People

(Reporter: vincent, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Iron/27.0.1500.0 Chrome/27.0.1500.0 Safari/537.36

Steps to reproduce:

The event onbeforeunload on the window element is used to ask the user if he really want to close (or change) the current page. It opens a popup window with two button and wait for a response from the user.

There is a bug in the process of window.onbeforeunload that allow the website to close the popup asking the user and force him to stay on the page. This way, it's impossible to close the tab or the window, the webpage refresh itself and we stay on the same page forever.

To reproduce this bug, you just have to create a web page and paste this code :
    <script type="text/javascript">
            function close ()
            {
                window.location.href = '';
                return true;
            }
            window.onbeforeunload = close;
        </script>

The " window.location.href='' " in the function, prevent the normal behavior of the browser.

(I've seen this behavior on a website that open a popup with an annoucement and prevent the closure using this method)


Actual results:

We see the popup asking if we really want to quit blinking, but it don't wait for an answer. The popup is closed immediately and we stay on the same page. It's impossible to close the tab nor the window (even with multiple tab opened).


Expected results:

The onbeforeunload event should not be bypassed and the user must be able to close the window at any time. The popup must wait for a response from the user.
Can you provide a link or testcase? Your script sample alone doesn't break anything in Firefox 31 for me. Try putting this in the location bar:

data:text/html,<script type="text/javascript">function close (){ window.location.href = '';return true}window.onbeforeunload = close;</script>


I can close that tab just fine.
Flags: needinfo?(vincent)
When I put the code in the location bar it doesn't work as if the code was in the page. My test page is on an intranet, you can't access it.

The page don't need to be hosted on the Internet, you can create a local page and access it with file:\\

This is the complete content of the page :
<!doctype html>
<html>
    <head>
        <script type="text/javascript">
            function close ()
            {
                window.location.href = '';
                return true;
            }
            window.onbeforeunload = close;
        </script>
    </head>
    <body>
        <p>Just a text</p>
    </body>
</html>
Flags: needinfo?(vincent)
Thanks! This is essentially the same issue as bug 1046022 - I've added your testcase there.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.