开发者

Inject <script> tag into <head> in code behind

开发者 https://www.devze.com 2023-04-01 08:03 出处:网络
I need to find a global way to inject a <script> tag into my pages directly within the <head> tag from the code behind.I开发者_如何学Pythons there something I can do in the global.asax?If

I need to find a global way to inject a <script> tag into my pages directly within the <head> tag from the code behind. I开发者_如何学Pythons there something I can do in the global.asax? If not, all my aspx pages inherit a class I have "BasePage" that implements System.Web.UI.Page.

Basically, I need a way to push jQuery into all of my pages "before" any other scripts (in the HEAD) are referenced.


protected void Application_EndRequest(object sender, EventArgs e)
{
    if (result)
    {
        Page page = HttpContext.Current.CurrentHandler as Page;
        if (page is Page)
        {
            page.ClientScriptManager.RegisterClientScriptBlock(this.GetType(), "HeadScript",
            "<script>alert('error')</script>");
        }
    }
}

Maybe something such as above works for you. Application_EndRequest is defined in Global.asax.


Check this out. It can be adapted to add to a master page too.

http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号