[英]How to include a certain javascript file after <body> tag
I'm getting an error TypeError: document.body is null
in javascript. 我收到错误
TypeError: document.body is null
javascript中TypeError: document.body is null
。
And the solution is found here. 解决方案在这里找到。 But the problem is that how can I load the specific javascript file(where the error come from) after
<body>
? 但是问题是,如何在
<body>
之后加载特定的javascript文件(错误来自哪里)? Or just add a window.onload = function()
to this file? 或者只是将
window.onload = function()
添加到此文件?
and especially, how to tell the path of the javascript file to the app? 尤其是如何判断javascript文件到该应用的路径?
I only know how to include every file into the application.js
, which would trigger before the <body>
load 我只知道如何将每个文件包含到
application.js
,该文件将在<body>
加载之前触发
Since you mention application.js
I assume you're using Rails? 由于您提到了
application.js
所以我假设您正在使用Rails? In that case, use javascript_include_tag
to include your file in the application.html.erb
just before the closing </body>
tag. 在这种情况下,请使用
javascript_include_tag
在</body>
标记之前将文件包含在application.html.erb
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.