ruby-on-rails - 使用带有 rails turbolinks 的插件
问题描述
Helpscout 提供了一个 javascript 插件来将信标/小部件添加到站点底部,如下所示:
<script>
!function(e,o,n){
window.HSCW=o,window.HS=n,n.beacon=n.beacon||{};var t=n.beacon;t.userConfig={},t.readyQueue=[],t.config=function(e){this.userConfig=e},t.ready=function(e){this.readyQueue.push(e)},o.config={
docs:{enabled:!0,baseUrl:"https://xyz.helpscoutdocs.com/"},
contact:{enabled:!0,formId:"xyz"}};var r=e.getElementsByTagName("script")[0],c=e.createElement("script");c.type="text/javascript",c.async=!0,c.src="https://djtflbt20bdde.cloudfront.net/",r.parentNode.insertBefore(c,r)
}(document,window.HSCW||{},window.HS||{});
HS.beacon.config({topArticles: true,poweredBy: false, topics: [{val: "help", label: "Help"}]});
HS.beacon.ready(function() {
HS.beacon.prefill({subject: "Support"});
});
</script>
在带有 turbolinks 的 Rails 应用程序上,这会在第一个页面加载后的每个页面加载时生成 JS 错误:“未捕获的 TypeError:无法读取 null 的属性‘createElement’”。
如何重新配置这样的脚本以使用 tublinks?
解决方案
你可以调用 javascriptpage:load
或turbolinks:load
$(document).on('ready page:load', function() {
// js code
});
或者
$(document).on('ready turbolinks:load', function() {
// js code
});
推荐阅读
- lua - 在重新定义对象时需要帮助
- firebase - Firestore - 批量查询 REST API 中的嵌套文档
- javascript - 如何创建 DeckGL 自定义数据源?
- javascript - 多个选择选项框在反应应用程序中无法正常工作
- jsf - 数据表中 Rowtoggle-ajax 事件的动作侦听器获取不正确的参数值
- sql-server - MongoDBODBC - 来自 MongoDB 客户端的错误:尚无符合重新扫描条件的服务器(错误代码:13053)
- java - 使用 Files.move 创建新的“文件”文件类型,而不是将文件移动到目录
- java - 为石英调度程序使用不同的数据源,该数据源在 spring boot 应用程序中使用
- r - 在 R/dplyr 中按条件最大值过滤
- sql - SQL 查询使用 row_number over partition by 获取聚合结果