Click to See Complete Forum and Search --> : Server Side Includes


bulgarian388
12-13-2006, 12:10 AM
Hi guys, quick question. Is it possible to create an asp file that creates a JavaScript file each time it is ran, and have it be included into the index page it needs to run in?

Thanks in advance.

russell
12-13-2006, 12:50 AM
sure

the include file

<%
Sub writeJSFile()
Dim fso
Dim tst
Dim jsFile

jsFile = "C:\inetpub\wwwroot\js\myJavaScriptFile.js"

Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.openTextFile(jsFile, 1, True)

tst.WriteLine "Some JavaScript Code" & vbCrLf
tst.WriteLine "Some More JavaScript Code" & vbCrLf

tst.Close
Set tst = Nothing
Set fso = Nothing
End Sub

Sub writeJSlink()
Response.Write "<script src=""/js/myJavaScriptFile.js""></script>" & vbCrLf
End Sub
%>

index.asp

<!--#include virtual="/includes/myIncludeFile.asp"-->
<%
writeJSFile
%>
<html>
<head>
<%
writeJSlink
%>
</head>
</html>

bulgarian388
12-13-2006, 01:27 AM
Great, thanks. I'm running into a permissions error, so it'll have to wait for now. Thanks again.