Hello,
I know nothing about JavaScript and right now I'm afraid I'm not in a position to research the answer to this myself.
A client requires that the "Settings have been saved" status messages (the ones in category 'status', and not those in categories 'error' or 'warning') should disappear after a certain time. In particular, when the user starts further editing (typing or clicking) it would be good if the message disappeared at that point.
Fade or sudden disappear, with or without repositioning of the rest of the page contents - none of that matters. I just need the 'status' messages to respond to a delay period (say 15 seconds), or to user activity, by disappearing.
I have a feeling that this would not be very hard. Any ideas anyone?
Thanks.
Comments
Comment #1
gilgabar commentedIt is fairly easy. Something like this should work for a timer:
And this should work if you want it to disappear when you click anywhere in the window:
I believe the growl effect also allows messages to be dismissed or disappear automatically.
Comment #2
martin_qThanks - where does this code go? Into some part of this module? Or in my theme?
Comment #3
gilgabar commentedIt's probably best to put it in your theme. You'll want to avoid making changes to contrib modules if you can help it.
If you already have a file for miscellaneous javascript in your theme, you could add it to that. Otherwise create a file in your theme called script.js (or whatever you want to call it). Add a line to yourtheme.info:
Then in script.js add:
That should do it. You may need to flush your caches to get script.js to load.
Comment #4
YK85 commentedHello,
Is it possible to make the message fade in, then fade out after 5 seconds OR mouseclick?
I would really appreciate your help!
Thanks
Comment #5
gilgabar commentedSure. It's pretty much the same as above. Just add an extra line to hide the message div initially and then fade it back in. And change the timer to 5000. Something like:
Comment #6
YK85 commentedsorry I am very new to all this and have a question.
Is the above for when using the Message Effects module?
If I'm not going to use the Message Effects module would the code be the same?
Many thanks!
Comment #7
gilgabar commentedIt is the same whether you use message effects or not.
Comment #8
YK85 commentedthank you!
Comment #9
martin_qThanks so much for all that help. Just one correction in case anyone else follows this thread. In order to get it to work, I needed to add a ) (and an optional ;) to the end of the code. So what I have ended up with is the following:
Comment #10
YK85 commentedI found the code at #9 and #5 compatible with some browsers but not with others.
Is there code to make messages disappear that is compatible with all browsers?
Thank you!
Comment #11
gilgabar commentedWhich browsers have trouble with it?
Comment #12
YK85 commentedhi gilgabar,
the browsers are Safari and Chrome
thanks
Comment #13
YK85 commentedHi again,
I was just wondering if anyone had any ideas for a better solution for browser compatibility across the major ones - IE7, IE8, Firefox, Safari, Google Chrome, in implementing messages to disappear after x seconds?
Thanks!
Comment #14
gilgabar commentedIt works fine for me in both Safari and Chrome. I just double checked. What specifically is the problem that you are having?
Comment #15
YK85 commentedThe message div hides but instead of the content underneath it moving up to where the message div used to be, the content doesn't move and there is an empty space (only in Safari/Chrome/other Webkit browsers)
Thanks!
Comment #16
gilgabar commentedSounds like a problem with your theme's CSS. It works perfectly for me using garland. The status message fades out and everything below it moves up in it's place. Tested in both Safari and Chrome. Try using garland to confirm that it is a problem with your theme.
Comment #17
ojchris commentedSuper, this #9 worked even 9 years after. Thanks guys