简体   繁体   English

将javascript代码片段附加到body标记的末尾

[英]Appending javascript code piece to the end of the body tag

I am looking for a way to insert javascript code block to end of ASP.NET page. 我正在寻找一种方法将JavaScript代码块插入到ASP.NET页面的末尾。

Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "showVideo", sScript, true);

is appending to body but js codes are always requesting some js files didn't load or some functions are below of the script. 是附加到body但js代码总是请求一些js文件没有加载或一些函数在脚本下面。

How can i append scripts that i generated dynamically to the bottom of body? 如何将我动态生成的脚本附加到正文的底部?

Thanks for your help. 谢谢你的帮助。

We are using something like 我们正在使用类似的东西

    public static void GenerateJsTag(this TemplateControl page, string jsCode)
    {
        var jsLink = new HtmlGenericControl {TagName = "script", InnerHtml = jsCode };
        jsLink.Attributes.Add("type", "text/javascript");
        page.Controls.Add(jsLink);
    }

hope that will help ;) 希望有所帮助;)

Adding Client-Side Script Blocks with RegisterStartupScript() and RegisterClientScriptBlock() 使用RegisterStartupScript()和RegisterClientScriptBlock()添加客户端脚本块

The only difference between these two methods is where each one emits the script block. 这两种方法之间的唯一区别是每个方法都会发出脚本块。 RegisterClientScriptBlock() emits the script block at the beginning of the Web Form (right after the tag), while RegisterStartupScript() emits the script block at the end of the Web Form (right before the </form> tag). RegisterClientScriptBlock() 在Web窗体的开头 (标签后面发出脚本块,而RegisterStartupScript() 在Web窗体的末尾 (在</form>标签之前发出脚本块。

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

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