开发者

How to block alert box through jQuery

开发者 https://www.devze.com 2023-01-20 23:22 出处:网络
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

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消