简体   繁体   English

Window.onload没有被调用[Ruby on Rails] [Vanilla Javascript]

[英]Window.onload not getting called [Ruby on Rails] [Vanilla Javascript]

I have a Ruby on Rails Application, with application.html.erb with the following body structure. 我有一个Ruby on Rails应用程序,其中application.html.erb具有以下主体结构。

<Header>
  <anchor tags></anchor tags>
</Header>
<%= yield %>

On clicking the anchor tags in the header -> the content of the yield changes. 单击标题中的锚标记->产量的内容会更改。 But the window.onload only loads one time ie when the page loads for the first time, despite navigating through the anchor tags in the header. 但是window.onload只加载一次,即页面第一次加载时,尽管浏览了标题中的anchor标签。 Due to which all the bindings and events which were handled inside the window.onload are getting lost. 因此,在window.onload内部处理的所有绑定和事件都将丢失。

How to add the same bindings and events when window.load is not getting called OR any alternative to window.onload using vanilla javascript that can solve the problem? 当未调用window.load或使用可解决问题的香草javascript替代window.onload时,如何添加相同的绑定和事件?

A possible reason for this behavior is turbolink gem. 出现这种情况的可能原因是turbolink gem。 Try to remove it if You haven't done it already. 如果尚未删除它,请尝试将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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