关闭rails视图时如何触发卸载事件?

时间:2014-10-02 18:48:38

标签: javascript jquery ruby-on-rails

在我的rails项目中,我想在关闭特定窗口时触发事件,假设我有主视图。

我可以通过添加以下内容来实现:

<script type="text/javascript">
    $(window).unload(function() {
      alert('hey');
    });
</script>

到/home/index.html.erb文件的末尾。

如果我将脚本移动到home.js.coffee,它将停止工作。

我想在关闭主页时触发警报,而不是其他页面,我该如何实现?

0 个答案:

没有答案
相关问题