简体   繁体   中英

Trying to handle window.onpopstate function

I'm trying to hadle how to work with window.onpopstate . I thought that it must hadle browsers back and forward buttons but it also handles any links... So why does it happen?

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <script>
        window.onpopstate = function( e ) {
            console.log("!!!!!!!!!!!!!!");
        }
    </script>

    </head>

    <body>

    <a href="#1">first</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#2">second</a>

    </body>
    </html>

It happens because that is what is supposed to happen.

The popstate event is fired when the active history entry changes.

MDN

Fired at the Window when the user navigates the session history

HTML 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM