programming-examples/asp/Strings/Remove Javascript from HTML.asp

26 lines
829 B
Plaintext
Raw Normal View History

2019-11-18 14:25:58 +01:00
<%
function clearJS(str)
clearJS = str
Set regEx = New RegExp
'This gets rid of onclick and such
oncmds = "Click|DblClick|KeyDown|KeyPress|KeyUp|MouseDown"&_
"|MouseMove|MouseOut|MouseOver|MouseUp"
regEx.Pattern = "(on("& oncmds &")[^>])"
regEx.IgnoreCase = True
regEx.Global = True
clearJS = regEx.Replace(clearJS, "")
'This takes out the ability to use javas
' cript: with href
clearJS = Replace(clearJS, "javascript:", "")
'This clears out < script > tags
regEx.Pattern = "(<[s]c[^>]*>)"
regEx.IgnoreCase = True
regEx.Global = True
clearJS = regEx.Replace(clearJS, "")
regEx.Pattern = "(</[s]c[^>]*>)"
regEx.IgnoreCase = True
regEx.Global = True
clearJS = regEx.Replace(clearJS, "")
End function
%>