简体   繁体   English

之后如何包含特定的javascript文件 <body> 标签

[英]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.

相关问题 如何在Body标签内调用Javascript文件 - How to call the Javascript file inside Body tag 如何在包含 jquery.js 之后但在仅使用 javascript 结束 body 标记之前在 html 文件中添加脚本标记? - How to add script tag in the html file after where jquery.js is included but before ending body tag using javascript only? 如何在WordPress中关闭/ body标签后添加Javascript - How to add Javascript after closing /body tag in WordPress 另一个加载后如何包含javascript文件? - How to include a javascript file after another loads? html 元素在 Javascript 文件之后加载,即使<script> tag is at the bottom of the <body> tag - html elements load after Javascript file even though the <script> tag is at the bottom of the <body> tag 屏幕一定大小时如何包含JavaScript文件? - How to include a JavaScript file when the screen is a certain size? 如何在页面的顶部将css文件包含到php中,在body标记结束之前包含js文件? - How do I include a css file into php in the head section of the page and a js file before the end of body tag? 如何在不使用脚本标记的情况下包含外部 javascript 文件 - How to include external javascript file without using the script tag 如何仅在 NextJS 中为某些页面关闭 body 标记后添加第三方脚本 - How to add third party script after closing body tag for certain pages only in NextJS Wicket 1.5正文标记中的Javascript文件 - Wicket 1.5 Javascript File in Body Tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM