Q: Including from file in a ASP

Discussion in 'ASP General' started by HJK, Jan 24, 2004.

  1. HJK

    HJK Guest

    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>
    HJK, Jan 24, 2004
    #1
    1. Advertising

  2. Re: Including from file in a ASP

    > 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

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/
    Aaron Bertrand [MVP], Jan 24, 2004
    #2
    1. Advertising

  3. HJK

    HJK Guest

    Re: Including from file in a ASP

    "Aaron Bertrand [MVP]" <> wrote in message
    news:...
    > > 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>?
    >


    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?
    HJK, Jan 24, 2004
    #3
  4. Re: Including from file in a ASP

    > 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

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/
    Aaron Bertrand [MVP], Jan 24, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vish
    Replies:
    2
    Views:
    1,712
    Steve C. Orr, MCSD
    Jul 16, 2003
  2. Joseph  Ferris

    ASP.Net page not including Javascript file.

    Joseph Ferris, Apr 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    769
    Ken Cox [Microsoft MVP]
    Apr 21, 2005
  3. Johan
    Replies:
    20
    Views:
    1,567
    Arndt Jonasson
    Feb 27, 2007
  4. Sarath
    Replies:
    9
    Views:
    206
    Roland Hall
    Jul 18, 2005
  5. Replies:
    2
    Views:
    119
    Henry
    Sep 26, 2007
Loading...

Share This Page