JavaScript: Vent! Er du virkelig sikker på, at du vil rejse?

StandsHave you ever gotten all the way to a submission page only to mess up and close the browser window? I have! I’ve actually gone through an entire purchasing system and added tons of items only to accidentally close the browser. Since most browsers support tabs now, it’s quite easy to do.

Applications that have a multi-step process, review and checkout would be wise to utilize a confirmation prior to the window closing… but it’s not as easy as you think. JavaScript has an onbeforeunload event where you can confirm whether or not the user really wants to leave the page. Here’s et eksempel and here’s the code:

En kommentar

  1. 1

    Yip, jeg har også oplevet det skøre lille problem i browservinduet. Faktisk har jeg søgt og fundet løsningen på dette problem, og jeg synes, det er lidt anderledes end din kode. Kun din kode ser godt ud og og forenklet den. Tak

Hvad mener du?

Dette websted bruger Akismet til at reducere spam. Lær, hvordan dine kommentardata behandles.