开发者

Alert that prevents any browser action until cleared

开发者 https://www.devze.com 2023-03-12 09:37 出处:网络
I\'m trying to validate text and I use an alert() to let the user know when the text isn\'t valid. My only problem is that, at least with FF4 for me, the alert doesn\'t do anything to block them from

I'm trying to validate text and I use an alert() to let the user know when the text isn't valid. My only problem is that, at least with FF4 for me, the alert doesn't do anything to block them from doing things like the back and forward buttons, so if the text isn't valid they can still press back and it will not be validated.

Is there a wa开发者_如何转开发y to make the alert so that nothing can be done to the browser until the alert is cleared away?


You can bind to window.onbeforeunload and make the user proceed the "correct" way until they get it right.

However, something tells me you need to fix your work-flow and not try to circumvent the user doing what they'd like (programmers always lose).


No, and there shouldn't be. There used to be truly modal alerts, but they were abused like crazy. Same as with no-URL popups and so on. It's a good thing we're rid of them.

In any case, as a web user, I'd expect the back button to always be safe and not leave the application in an inconsistent state. That's probably a better approach


I can't really think of anything that is so important to validate to prevent any other functionaluty and you can never truly achieve this on the client side and if you really have to then you should set a variable on the serverside, in the database for that user lets call it user_preventaction and lets say you set it to TRUE when the page loads that will not change until the input you want is validated and set back to FALSE. Then any page the user tries to access and preventaction is still TRUE it will render a page forcing them to validate whatever you think is so important that the user can even decide to go back.


Even though you can replace the browser's alert box, the functionality is still built-in to the browser, so I don't think you can.

It would be better to consider alternative forms of error display.

0

精彩评论

暂无评论...
验证码 换一张
取 消