开发者

How to block alert box through jQuery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜