javascript - 为特定 block 使用 CSS(作用域 CSS)

标签 javascript jquery html css

我有一个应用程序,用户可以在其中粘贴他们的 html 代码,每当我用 style 标签粘贴 html 时,这些 CSS 规则也会应用于我的应用程序。

那些 CSS 规则应该只应用于粘贴的代码。

找到这个:

http://www.w3schools.com/tags/att_style_scoped.asp

但它只适用于 firefox,将是这个问题的完美解决方案。

现在我正在考虑解析粘贴的 CSS 规则并将它们作为内联 css 规则应用于 html。

有没有更好的解决方案?

最佳答案

使用 iFrame 提供安全的方式来显示用户提供的 HTML 代码。这样,即使用户试图覆盖您的网站以使其看起来像银行帐户,他仍然无法访问外部 iFrame 内容。

关于javascript - 为特定 block 使用 CSS(作用域 CSS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40528743/

相关文章:

html - Div 不会在另一个 div 中居中

html - 如何在 css 中保持焦点

javascript - jquery 和 javascript native

javascript - Gulp.js : task based on forEach loop

javascript - 为什么 lodash.isError 需要存在?

JavaScript/Node : Path on Ubuntu

javascript - 通知小部件不会每隔两次打开一次

jquery - 更改 jQuery UI 中选项卡的 CSS

html - 溢出 :hidden dots and the end of a multiline text

javascript - 如何通过类名获取元素