- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:32 AM
We have a requirement where they want to automatically close info message(g_form.addInfoMessage) after 30 sec. In order to do that i have to find and write time out to each info message in system.
I am looking for is there anyway we can define it globally at some place so where ever the info message is written it will take 30 sec to time out only?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:55 AM
Yes, you can create a client script that automatically detects and closes all info messages after 30 seconds without modifying each individual message. Here's the most effective approach:
function onLoad() {
// Override addInfoMessage to mark auto-close messages
var originalAddInfoMessage = g_form.addInfoMessage;
g_form.addInfoMessage = function(message, persist) {
var msgElement = originalAddInfoMessage.call(this, message, persist);
if (!persist) {
msgElement.dataset.autoclose = 'true';
}
return msgElement;
};
// Check for messages every second
setInterval(function() {
var messages = document.querySelectorAll('[data-autoclose="true"]');
messages.forEach(function(msg) {
if (!msg.dataset.closeTime) {
msg.dataset.closeTime = Date.now() + 30000;
} else if (Date.now() > parseInt(msg.dataset.closeTime)) {
$(msg).fadeOut(500, function() {
$(this).remove();
});
}
});
}, 1000);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 04:00 AM
Will this work for catalog client scripts as well ?
