[thelist] Re: how to gen included client-side javascript from ASP?

pouncyisdead pouncy_1 at hotmail.com
Thu Jan 8 16:42:01 CST 2004


Make sure you are stripping out string fragments that kill javascript (js
special chars, linebreaks, quotes).

I've found it's easiest to escape in server-side js, and unescape on the
client-side.

EXAMPLE:
=============
<script language="javascript" runat="server">
    function jsEscape(textStr) {
        return escape(textStr);
        }
</script>
<%

Dim sOutPut, strBody, strLine

    '-- String to Output
        sOutPut = "**Text/HTML whatever to unescape.**"

    '-- Escape string:sOutPut here
       strLine = jsEscape(sOutPut)

    '-- start the ASP/JS conversion
        strBody = "var sHTML = "
        strBody = strBody & "'" & strLine & "' +" & vbCrLf
        strBody = strBody & "''; "
        strBody = strBody & "sHTML = unescape(sHTML); "
        strBody = strBody & "document.write(sHTML);"
    '-- End the ASP/JS conversion


    '-- Write the JS code
        With Response
            .ContentType = "text/javascript"
            .Write "<!-- <![CDATA[" & VbCrLf
            .Write strBody
            .Write VbCrLf & "// ]]> -->"
        End With

%>
=============




Mike Pouncy - DorkExtraordinaire
  "All you can see is your brutal success / And damn the dead and fear the
mess." - CRASS ©1995 [ Best Before {Don't tell me you care} ]
Em: pouncy_1 at hotmail.com  |  Http: http://www.vegasGoths.com/


---------------
[snip src="James Aylard" subj="client-side javascript from ASP"]
This should work, and did in a simple test that I created.

I'm using IE 6 to test.  Yes my server is parsing ASP.  I can reference the
ASP directly, and it will display the javascript.  Hmmm... I've got a
feeling I'm missing something very basic.
[/snip]


More information about the thelist mailing list