I've tried using the Sanitize
gem to clean a string which contains the HTML of a website.
It only removed the <script>
tags, not the JavaScript inside the script tags.
What can I use to remove the JavaScript from a page?
Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled. The yellow warning icon next to Sources reminds you that JavaScript is disabled.
Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.
I am partial to the Loofah gem. Modified from an example in the docs:
1.9.3p0 :005 > Loofah.fragment("<span onclick='foo'>hello</span> <script>alert('OHAI')</script>").scrub!(:prune).to_s
=> "<span>hello</span> "
You might be interested in the ActiveRecord extensions Loofah provides.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With