javascript - Best way to ask confirmation from user before leaving the page -
i building registration page if user leaves, want pop css box asking him if sure or not. can accomplish feat using confirm boxes, client says ugly. i've tried using unload , beforeunload, both cannot stop page being redirected. using events, return false, maybe there's way cancel other returning false?
another solution i've had redirecting them page has popup, problem if want leave page, , wasn't mistake, lose page trying go to. if user, irritate me.
the last solution real popup window. thing don't main winow have destination page while pop have page. in opinion looks disjoint. on top of that, i'd worried popup blockers.
just add everyones comments. understand irritating prevent users exiting page, , in opinion should not done. right using confirm box @ point. happens it's not "preventing" user leaving, client wants make suggestion if user having doubts registering. if user halfway through registraiton process , leaves reason, client wants offer user free coupon seminar (this client selling seminars) persuade user register. client under impression since user on form, thinking of registering, , therefore maybe seminar of registering final push user register. ideally don't have prevent user leaving, good, , in opinion better if can pause unload process. maybe sleep command? don't have keep user on page because either way leaving go different page.
also, people have stated, terriable title, if knows better one, i'd appreciate if change title no spammer inviting.
as saw words "prevent user" started wail in agony. never prevent user, them.
if see registration page , run off, that's their choice. pop javascript confirm box if they've filled in data (because might navigating away accidentally) leave @ that. if haven't touched form, leave them alone - don't want fill in form.
look @ other methods of engaging users. if form huge , scary, break simple manageable chunks or better yet, simplify things user gives data when need it. example, might not need address until want post them.
by breaking multiple parts can hook them simple form , once they've invested time, they'll more continue process.
but don't harass users. if don't want register, pestering them pop-ups , jaavscript dialogues chase them off site completely.
with in mind, assuming you're trying stop people half-filling-in forms, there couple of options genuinely people:
detect if form has changed , ask them simple
confirm()
message.this can do. css "pop-in" won't work because can't control* window location in unload event.
*you can put event listener on page's links fire off check form, helps if user clicks on 1 of links. won't if, example, user clicks or closes window. could both css , javascript end bit of mess.
persist state of form behind scenes.
an extension #1. instead of squabbling user, let them go want save content of form either session or cookie (if it'll fit) , put on page (like so's orange prompt bars @ top of page) reminds them they've started filling in form , gives them link form.
when click link, load data out of cookie (or session) form , let them carry on. has clear benefit of letting them on site , keeps data safe.. ish.
if don't come , cookie/session expire, that's fault. can lead horse water. it's not job force drink.
Comments
Post a Comment