Asp for JScript trap one: character escape

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Wrong usage:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%
    var path1="C:\mydir\img";
    var path2="C:\\mydir\\img";
%>
<html>
<head>
     <script>
           var i="<%=path1%>";
           var j="<%=path2%>";
           alert(i); //Output C:mydirimg
           alert(j); //Output C:mydirimg
     </script>
</head>
</html>

Reason:

Because I is path1 output value, which is the escape character, so I the value is C:mydirimg, and the

J although the value is C:\mydir\img, but j is still a JS variable, so, or escape character. Open the view like this:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%
    var path1="C:\mydir\img";
    var path2="C:\\mydir\\img";
%>
<html>
<head>
     <script>
           var i="C:mydirimg";     //i="<%=path1%>";
           var j="C:\mydir\img";  //"<%=path1%>";
           alert(i); //Output C:mydirimg
           alert(j); //Output C:mydirimg
     </script>
</head>
</html>

Correct usage:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%
    var path1="C:\\\\mydir\\\\img";
%>
<html>
<head>
     <script>
           var i="<%=path1%>";
           alert(i); //Output C:\mydir\img
     </script>
</head>
</html>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Ashley at November 14, 2013 - 3:54 AM