The other day I ran into the situation where I submitted my form with Ajax and then sent the message. The following two functions are then written to solve the two problems.
The first function turns the data in HTML into an HTML entity, and the HTML tag does not turn, so no matter where it is, you can choose to send an HTML message when you send the message.
The second function of the JS data is also replaced by the escape character, also avoids the JS keyword and other characters of the conversion, no matter what the page is encoded it will not garbled. Less nonsense, look at the code below.
Copy Code code as follows:
Function htmlentities (str)
Dim A,i,char
For i = 1 to Len (str)
char = Mid (str, I, 1)
A=ASCW (char)
If a > 128 Or a < 0 Then
Htmlentities = htmlentities & "&#" & CLng ("&h" & Hex ((ASCW (char))) & ";"
Else
Htmlentities = htmlentities & Char
End If
Next
End Function
Function Unicode (STR1)
Dim str,temp
str = ""
For I=1 to Len (STR1)
temp = Hex (AscW (Mid (str1,i,1))
If Len (temp) < 5 Then temp = right ("0000″& temp, 4)
str = str & "\u" & Temp
Next
Unicode = str
End Function
If you're holding it in your hand, then you can use whatever you want, of course, there are times when we rewrite some code to meet the needs of a particular situation, and if you're reporting a study and research attitude, it's worth noting that the ASCW (char) function might return a long integer value. and ASP regard it as an integral type, need to do small processing.