开发者

Dynamically return a javascript file in Classic ASP

Is it possible to have an asp page return a javascript file dynamically in classic ASP? What I'm trying to do is return a specific javascript file to a calling asp page by passing through another asp page. 开发者_如何学PythonThe 'pass through' page will inspect a server variable and based on a setting with either return scriptA.js or scriptB.js to the calling asp page. The calling asp page needs to use the returned .js for navigation menus.

It's been over 7 years since I've done any Classic ASP, and got sucked into helping out on a project.

Any help is appreciated.

Thanks!


You'd have to use Server.CreateObject("Scripting.FilesystemObject") to read the appropriate javascript file and use Response.Write to output the appropriate javascript file. Remember to set the content type to JavaScript.

Response.ContentType = "application/x-javascript"


You can dynamically include files like this:

if Request.QueryString("param")="2" then  
    Server.Execute("page1.asp") 
else 
    Server.Execute("page2.asp") 
end if 

Where page1.asp and page2.asp have js files embedded in them (only).


Something like:

<script type="text/javascript" src=<%
if($Request->ServerVariables(URL)->item() eq 'here') { %>"something.js"<% }
else {  %>"somethingelse.js"<% }
%>></script>


Using JScript in Classic ASP

var curFileName = "";
if(Server("Variable") == 'true'){ curFileName = page1.js; }
else{ curFileName = page2.js; }

Response.Write("<script type='text/javascript src='" + curFileName + "'><\/script>");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜