【发布时间】:2014-11-26 05:51:30
【问题描述】:
我有一个 web 视图,我需要在其中加载一些 html text。但现在我的问题是当有人输入这样的脚本时
foo<script>alert('omg hacked')</script>bar<br>
当时它在加载 html 时发出警报。
如何避免这种情况?
提前致谢。
【问题讨论】:
标签: javascript ios iphone uiwebview
我有一个 web 视图,我需要在其中加载一些 html text。但现在我的问题是当有人输入这样的脚本时
foo<script>alert('omg hacked')</script>bar<br>
当时它在加载 html 时发出警报。
如何避免这种情况?
提前致谢。
【问题讨论】:
标签: javascript ios iphone uiwebview
您可以使用 xmp 标记来阻止 script 执行。如下所示
yourHtml = [yourHtml stringByReplacingOccurrencesOfString:@"<script>" withString:@"<xmp style='display:inline'><script>"];
yourHtml = [yourHtml stringByReplacingOccurrencesOfString:@"</script>" withString:@"</script></xmp>"];
【讨论】: