conditional javascript in .ascx
I have a javascript src that i need to add to some of the pages in a site.
for example
<script type="text/javascript" src="http:abcxyz.com/zzz"></script>
I want to add th开发者_如何学运维is conditionally on a .ascx page - if the Request.ServerVariables["SCRIPT_NAME"]
ends with certain criteria.
The ascx language is vb, and there is no code behind.
Thanks
If you make it so the tag is runat=server, you should be able to conditionally add the code as script:
<head runat="server">
<% If Request.ServerVariables("SCRIPT_NAME") = "value" Then %>
<script type="text/javascript" src="whatever.js"></script>
<% Else %>
<script type="text/javascript" src="whatever_else.js"></script>
<% End If %>
</head>
No code behind, but still code in front right?
This will probably do it...
<%= If(Request.ServerVariables("SCRIPT_NAME").EndsWith("<criteria>"), "<script type='text/javascript' src='http:abcxyz.com/zzz'></script>", "")%>
精彩评论