0

I am on rails3, and Turbo-links causes the link for zendesk to not work.

I was using zendesk script and that was not loading on next page and then I have used script that mentioned here. It seems working fine on chrome, but on Firefox and Safari, its still causing problem.

I have included below lines into my layout:

= javascript_include_tag 'zendesk', 'data-turbolinks-track' => true

:javascript
  document.addEventListener('page:change', zendesk_web_widget());

and zendesk_web_widget() is function that loading widget.

I have searched around web and found some solutions but not working at all:

Rails 4 turbo-link prevents jQuery scripts from working

https://github.com/turbolinks/turbolinks-classic/issues/166

Any anyone has any idea then please let me know.

Community
  • 1
  • 1
Vik
  • 5,955
  • 3
  • 27
  • 37

1 Answers1

1

You are passing the return value of the function zendesk_web_widget to the listener, not the function itself. So instead of calling the function (with ()), try passing the function:

document.addEventListener('page:change', zendesk_web_widget);

Or, making a wrapper function for it:

document.addEventListener('page:change', function () { zendesk_web_widget(); });

And since you're using jQuery, why not make the code use jQuery.

$(document).on('page:change', zendesk_web_widget);
ollpu
  • 1,518
  • 13
  • 25
  • Thanks Ollpu for your response, but when I add wrapper function then it works into Firefox but not into Chrome, and reverse if I remove :( – Vik Sep 19 '16 at 03:41
  • 1
    Also make sure that the function is executed on initial page load, with something like `$(document).ready(zendesk_web_widget);` – ollpu Sep 19 '16 at 05:53
  • thanks @ollpu, its helping me to run at one level ahead. – Vik Sep 20 '16 at 03:55