Reputation: 10448
I want to block alert box if it is present in code. Im using an api that tells me the search result of my website and if any user enter
<script>alert('Just teasing')</script>
then it shows an alert box on my page how can i stop this alert?
Upvotes: 2
Views: 3202
Reputation: 114825
First of all you should sanitize you input as @Nikita commented.
If you want to accept JavaScript and only disable alert
you can replace the window.alert
function.
window.alert = function() { /* do nothing here */ }
Now calling alert
won't do anything.
Upvotes: 8
Reputation: 43114
When presenting the search results back to the user you need to ensure you HTML encode the output so the user would see the script rather than it being executed.
Upvotes: 4