Reputation: 1229
I have some old code that I am supposed to touch up, and it appears someone included classic asp code inside a .js file in order to render a javascript function based on some session variable values, but i receive a 'syntax error' when rendering the page, which i am trying to resolve. the code is as follows;
<% if Session("Money_Guide_Pro_Application_Granted") = "Y" then %>
function OpenMGP()
{
var oNewWindow = "MGP";
window.open("https://" + "<%=Request.ServerVariables("SERVER_NAME")%>" + "/applications/commlink/MGPRO/MGProRepSelect.aspx",oNewWindow,"height=600,width=667,status=no,toolbar=no,scrollbars=yes,menubar=yes,resizable=yes,location=no");
}
<% else %>
function OpenMGP()
{
var oNewWindow = "MGP";
window.open("https://" + "<%=Request.ServerVariables("SERVER_NAME")%>" + "/backoffice/Planning/MGPNoSub.asp", oNewWindow,"height=400,width=500,status=no,toolbar=no,scrollbars=yes,menubar=yes,resizable=yes,location=no");
}
<% end if %>
basically to use a different url when opening up the window depending on the users permissions that are set. I thought this wasn't possible because classic asp is server side and all .js is client side so I figured once the client hit this .js file it wouldn't be able to parse server side code. any help would be appreciated.
Upvotes: 0
Views: 3575
Reputation: 1
You could give that .js file a .asp extension if you like, and include it like this to avoid having to use server side includes:
<script src="../Include/YourFileName.asp?x=1&y=2" type="text/javascript"></script>
It is then usually a good idea for the first line of that .asp page to be this:
<%Response.ContentType="text/javascript"%>
Upvotes: 0
Reputation: 4638
A .js file would need to be entirely written in client side JS. The stuff inside <% %> is server side VBScript. As an external javascript file it's useless, but you could use it as a server side include in a .asp page, ie
<script type="text/javascript">
<!--#include file ="yourfilename.js"-->
</script>
In this situation the extension of the include file doesn't matter, as the server will treat it as if it's part of the page it's rendering. It's considered good practice however to also give include files the .asp extension.
Upvotes: 3