简体   繁体   中英

Remove JavaScript code from HTML

I'm looking for C# regular expression to replace/remove all JavaScript from HTML. Can someone please help me with the code?

Removing just the <script> tags won't actually do it. That's because you can put Javascript in event handlers too (onclick, etc). They're a lot harder to catch with a regular expression.

Once again, we revisit the issue or parsing or processing HTML with regular expressions. It's the wrong tool for the job. If you don't want flaky code, use an HTML parser.

Why do you want to filter javascript?

If you are trying to prevent cross-site scripting attacks in a web application you're probably better off using a well-tested library for that purpose. It looks like Microsoft has an AntiXSS library, which may be of use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM