admin管理员组文章数量:1399992
My user is filling out a small form (just the email address) and I send this data to the server via javascript. I send the form, then clear the data from the fields.
Is it bad practice to simply give the user a js alert like alert('Your email has been added')
as opposed to adding markup to display the message? I don't see it often today, so I'm wondering if it reflects some perception that using alerts isn't good. It makes the code much easier though, and I wonder why not!
And a side question, is it possible to just style this alert so it doesn't look so bad?
My user is filling out a small form (just the email address) and I send this data to the server via javascript. I send the form, then clear the data from the fields.
Is it bad practice to simply give the user a js alert like alert('Your email has been added')
as opposed to adding markup to display the message? I don't see it often today, so I'm wondering if it reflects some perception that using alerts isn't good. It makes the code much easier though, and I wonder why not!
And a side question, is it possible to just style this alert so it doesn't look so bad?
Share Improve this question asked Feb 7, 2011 at 10:42 zmolzmol 2,9045 gold badges30 silver badges30 bronze badges 2-
It's funny you should mention that. I'm in the middle digging through the Markitup source code to replace uses of
prompt
(likealert
but with a text input) with nicer modal dialogs. – aaronasterling Commented Feb 7, 2011 at 10:46 - as an user, I would prefer a message than an alert box. in your case particularly, by showing the html message directly, you would be saving the user of a click to close the alert – naiquevin Commented Feb 7, 2011 at 10:48
8 Answers
Reset to default 2alert
interrupts the user in whatever he was doing. That's not good and should only be done if it is absolutely necessary. An alert
is not necessary, because the user has only one way to continue anyway.
It's not a very pleasant user experience when popup alerts keep appearing. Annoying as they interrupt what you are doing and you have to click on a button to carry on what you are doing. Excessive use makes it very unlikely that they will ever be read, causing big problems when something actually important es up or the user has to make a choice.
Having more sophisticated feedback in the interface creates a much better experience.
Since you tagged this with jquery
$('#my-form').prepend('<p class="notice">Your email has been added</p>');
Was that really so hard?
If the main purpose of your page is to collect the email address I think it is perfectly valid to use an alert box.
I think the main reason you don't see this practise any longer, is that you have limited possibility to style the alert box.
I.e. it is not very Web 2.0
"And a side question, is it possible to just style this alert so it doesn't look so bad?" Nope. And you can't change the title, design or anything like that, it's purely browser dependant!
I for one find it annoying when alerts pop up left right and centre, they're modal so you HAVE to click on them and while they were used a lot for that back in the day, these days it's generally much more accepted to write something into the web page. This has a number of advantages over an alert dialog:
- You can skin it to suit your needs entirely
- It doesn't annoy the user as much
- Sometimes browsers these days can prevent sites from displaying alert dialogs at all (because they're so annoying)
- An alert dialog disappears as soon as you click OK, you have to remember what it was moaning about or what it said. If it's built into the page then this information remains there for you to see.
If you genuinely need a modal-like dialog box these days (and for this case I'd say you didn't) it's far more mon to use a JS library to emulate one. That way you can get the exact behaviour you want, it can look in keeping with the web page and can't be turned off by the browser.
alert() is largely seen as a non-graceful solution in terms of UI design these days. With that in mind, it really es down to the environment - if it's a public facing consumer website, I avoid using alert() whenever possible as it disrupts the user's flow. If it's a backend-style corporate website, screw it, an alert can work fine there (but still use your judgement, lightweight markup never hurt anyone).
They're annoying, break the flow and personally I think they're only appropriate for 'alerting' users to something. Something like a message to inform you that you've been registered which is more 'confirmation. and the expectation in these Web 2.0 days is that such things appear in a more permanent form on the main webpage/ GUI.
In my opinion it's quite obtrusive as it blurs the difference between harmless web error messages (for example, you forgot to enter your password!) and more serious application errors.
Also if you don't handle them properly, you can't get 3-4 consecutive errors which is extremely annoying.
It's easy and quick to implement however, gets the user attention, and guarantees they won't be able to do anything until they have seen and pressed ok on the error message.
As for styling, you can't. But take a look at jGrowl, it has a really nice way of doing error messages.
本文标签: javascriptIs it frowned upon to use js alerts with userStack Overflow
版权声明:本文标题:javascript - Is it frowned upon to use js alerts with user - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744120616a2591722.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论