【问题标题】:Load Script as a text in UIWebView在 UIWebView 中将脚本作为文本加载
【发布时间】:2014-11-26 05:51:30
【问题描述】:

我有一个 web 视图,我需要在其中加载一些 html text。但现在我的问题是当有人输入这样的脚本时

foo<script>alert('omg hacked')</script>bar<br>

当时它在加载 html 时发出警报。

如何避免这种情况?

提前致谢。

【问题讨论】:

    标签: javascript ios iphone uiwebview


    【解决方案1】:

    您可以使用 xmp 标记来阻止 script 执行。如下所示

    yourHtml = [yourHtml stringByReplacingOccurrencesOfString:@"<script>" withString:@"<xmp style='display:inline'><script>"];
    yourHtml = [yourHtml stringByReplacingOccurrencesOfString:@"</script>" withString:@"</script></xmp>"];
    

    【讨论】:

      猜你喜欢
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      相关资源
      最近更新 更多