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?
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?
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.
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.