Answers.Body: <p>Craft's JS/UI framework &quot;Garnish&quot; is largely undocumented, but exploring the <code>Craft</code> object it exposes in the console, I found a few methods that might be useful:</p>
  <pre class="lang-js prettyprint-override"><code>// Good for confirmations (blue banners):
  Craft.cp.displayNotice('Your changes have been saved.');
  
  // Good for errors (red banners):
  Craft.cp.displayError('Uh oh, something bad happened!');
  
  // Custom flash names (for anything else—requires custom CSS):
  Craft.cp.displayNotification('custom-flash-key', 'Something very special happened!');
  </code></pre>
  <p>The last one, <code>displayNotification</code> is the abstract method, called by the first two. <code>custom-flash-key</code> gets added to the notification as a classname.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-02T20:40:25.840Z
Answers.Text: How could these be set from a module?
Answers.UserDisplayName: Augustine Calvino
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-16T16:59:02.353Z
Answers.Text: how to do this with craft 4?
Answers.UserDisplayName: tenshi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-19T17:52:01.263Z
Answers.Text: @AugustineCalvino Generally speaking, flashes set from the back-end (i.e. a controller) should go through `Craft::$app->getSession()->setNotice($message)` and `->setError($message)`. Craft will automatically render those notifications for you when the page loads!
Answers.UserDisplayName: August Miller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-19T20:19:02.500Z
Answers.Text: @tenshi This still applies to Craft 4. 4.2.0 introduced rich notifications, which means these JavaScript methods now support additional arguments—haven't had a chance to document this, yet, though!
Answers.UserDisplayName: August Miller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-22T23:23:37.277Z
Answers.LastActivityDate: 2020-11-22T23:23:37.277Z
Answers.UserDisplayName: August Miller
Body: <p>Is there any js function that will display these notifications that appear on top of the screen? Flash messages use these notifications, but I don't want to use flash messages, I want to display notification without refreshing a page.</p>
  
Tags: <control-panel>
Title: Displaying notification in control panel
ThreadText: # Displaying notification in control panel
  
  (Asked by: username_0 on 2020-11-22)
  
  Is there any js function that will display these notifications that appear on top of the screen? Flash messages use these notifications, but I don't want to use flash messages, I want to display notification without refreshing a page.
  
  **Tags:** control-panel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-11-22. Score: 5 | Accepted answer
  
  Craft's JS/UI framework "Garnish" is largely undocumented, but exploring the `Craft` object it exposes in the console, I found a few methods that might be useful:
  
  ```js
  // Good for confirmations (blue banners):
  Craft.cp.displayNotice('Your changes have been saved.');
  
  // Good for errors (red banners):
  Craft.cp.displayError('Uh oh, something bad happened!');
  
  // Custom flash names (for anything else—requires custom CSS):
  Craft.cp.displayNotification('custom-flash-key', 'Something very special happened!');
  
  ```
  
  The last one, `displayNotification` is the abstract method, called by the first two. `custom-flash-key` gets added to the notification as a classname.
  
  > **Comments:**
  > **username_2**: How could these be set from a module?  
  > **username_3**: how to do this with craft 4?  
  > **username_1**: @username_2 Generally speaking, flashes set from the back-end (i.e. a controller) should go through `Craft::$app->getSession()->setNotice($message)` and `->setError($message)`. Craft will automatically render those notifications for you when the page loads!  
  > **username_1**: @username_3 This still applies to Craft 4. 4.2.0 introduced rich notifications, which means these JavaScript methods now support additional arguments—haven't had a chance to document this, yet, though!  
  
  ---
  
  