简体   繁体   中英

Why is my javascript not triggering when using Turbolinks, even with the correct event listener?

I have run into these issues before, so I know I need to listen to a specific event to trigger my javascript that's rendered on a page. I'm trying the following, but when using a Turbolink to get to this page, the JS isn't working:

:javascript
  $(document).on("turbolinks:load", function() {
    alert('hello')
  })

So whenever I type the URL, I refresh the page, or come via a redirect, this works fine. As soon as I come into the page via a (turbo)link it is not. I'm a bit lost, because this exact event listener is how I read it in the docs: https://github.com/turbolinks/turbolinks#observing-navigation-events

$(document).ready(function() {

//Your code here

});

Instead of using turbolinks:load. Did you try using this instead?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM