Q: Including from file in a ASP

H

HJK

I'm not familiar with ASP and server side scripting.

I want to include JScript from file. Can it be done ?

Its the part with the Options code I want to put in a Options.js
file not accessible from internet side. It will also be nice to extend it
to include
from different .js files later.

See my ASP example below wich I get to work in IIS 5.0

<% @Language = "JScript" %>

<%
// want to run the following code from file...
var Options
Options="\<option value=\>Line1\<\/option\>";
Options+="\<option value=\>Line2\<\/option\>";
Options+="\<option value=\>Line3\<\/option\>";
Options+="\<option value=\>Line4\<\/option\>";
%>

<html>

<head>

</head>


<form method="post" name="myform">


<table border="1" >
<tr>
<select name="MyListBox" size="10" style="FONT-FAMILY: Trebuchet MS">
<%
Response.write(Options);
%>

</select>
</tr>


</table>
</form>

</body>
</html>
 
A

Aaron Bertrand [MVP]

See my ASP example below wich I get to work in IIS 5.0

Did you try <!--#include file=options.js--> or <script language=jscript
runat=server src=options.js></script>?

A couple of notes:

- a user typing in http://www.yoursite.com/yourfile.js will be able to read
the file in plain text. If you have anything you want to keep "secret" from
casual viewers, use the ASP extension. See http://www.aspfaq.com/2163 and
http://www.aspfaq.com/2269

- if your goal is to use a .js file in both server-side and client-side
script, see http://www.aspfaq.com/2208

- if you are mixing JScript and VBScript in a single page, there are "order
of operations" issues to consider; see http://www.aspfaq.com/2045
 
H

HJK

Aaron Bertrand said:
Did you try <!--#include file=options.js--> or <script language=jscript
runat=server src=options.js></script>?

Thank you. Include works well and imports the listbox content OK.
I actually ended up using <% Server.Execute("sites.ASP") %>

However I struggle to protect my javascripts in existing html pages. Thats
my goal.

One example is
http://home.online.no/~jensts/Satellite/Elevation.htm

It calls a jscript using <script src="filename" ></script>

Inside the pages I use onchange trigged functions from the jscript file.

I've tried for several days to make it as ASP but the only way to get it to
work is to give the scriptfile read access from internet side.

Also to run the script containing script functions at server or as
Server.Execute("file.ASP") causes the onchange event to
result in uknown object.

Perhaps ASP is not the best way of doing this ? - Could there be better
alternatives for this?
 
A

Aaron Bertrand [MVP]

Perhaps ASP is not the best way of doing this ? - Could there be better
alternatives for this?

For hiding client-side JavaScript? If my browser can see it (and it has to
in order to run it), so can I. So, if you don't want anyone to see it
online, don't put it on the web. If you don't want anyone to see it period,
delete it from your computer and uninstall undelete.

http://www.aspfaq.com/2175
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top