简体   繁体   English

如何在之前添加脚本代码 </body> 标记ASP.NET

[英]How to Add script codes before the </body> tag ASP.NET

Heres the problem, 继承人这个问题,

In Masterpage, the google analytics code were pasted before the end of body tag. 在Masterpage中,google分析代码在body标记结束之前粘贴。

In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript and put it before the end of body tag, because this script uses the google analytics variables. 在ASPX页面中,我需要使用codebehind ClientScript生成一个脚本(google addItem tracker)并将其放在body标记的末尾,因为此脚本使用了Google Analytics分析变量。

How can i achieve this? 我怎样才能实现这一目标?

Take a look at RegisterStartupScript 看看RegisterStartupScript

The script block will be placed right above the </form> tag at the end of the page. 脚本块将放置在页面末尾的</form>标记的正上方。

如果您能够避免使用ClientScript ,那么一种不优雅但简单的方法就是在您想要渲染脚本的页面中粘贴一个文字,并将脚本放在代码隐藏中(即myLiteral.Text = "client script"; )。

您可以延迟脚本执行,直到页面加载为止,然后脚本所在的位置无关紧要。

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

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