1

I am just wondering if there is any way to do this?

Basically, I have some javascript that I want to execute after the user has closed the flash notice which appears when the page loads. Do I have to make a custom flash notice to get an event handler on it or is there a way to get a handler on the built-in rails flash notice?

John Naegle
  • 7,927
  • 3
  • 36
  • 47
Jeff Pole
  • 327
  • 2
  • 3
  • 12

2 Answers2

1

You can easily bind a jquery event handler to the user clicking on the button to dismiss the flash notice..

$().ready(function() {
  $("#button_id_that_user_clicks_to_dismiss_the_flash_notice").click(function() {
    alert("user has dismissed the flash notice")
  })
})

your flash element is probably located in app/views/layouts/application.html.erb .. edit this file to ensure that you properly id the dismissal button

ilan berci
  • 3,842
  • 1
  • 14
  • 20
0

This is assuming you're using coffeescript, which is currently default in Rails:

jQuery ->
  $('#flash_close_button').on 'click', (ev) ->
    # close flash notice
    # do other stuff here

This will require you to edit the html for the flash notices. To do this without an identifier, you might want to see this answer.

Community
  • 1
  • 1
Damien Roche
  • 12,611
  • 16
  • 66
  • 90