LeeReamond
V2EX  ›  问与答

html 有办法注入一个 iframe 内部,修改里面的 css 样式吗?

  •  
  •   LeeReamond · Feb 9, 2021 · 1650 views
    This topic created in 2117 days ago, the information mentioned may be changed or developed.

    如题,现有一个需求是,自己使用 vue 搭建的 web 服务中,有页面是利用 iframe 直接嵌入别人做好的页面,因为做出来看效果挺好的,没必要再修改,而如果手动迁移到 vue 组件的话又太累了,所以就直接用 iframe 调用了。但是现在想添加一些动态响应的内容,比如应用切换到夜间模式的时候,该页面的背景颜色也能同步改成黑色之类的。

    印象中有一些注入方式,很久没做过忘光了,有没有大佬能指点一下怎么做。

    所有网页都是同源的,没有跨域问题

    kkocdko
    kkocdko
    Feb 9, 2021❤️1
    1
    iframe.contentWindow == 在 iframe 里头的 window
    iframe.contentDocument == 在 iframe 里头的 document
    LeeReamond
    LeeReamond
    OP
    Feb 9, 2021
    2
    @kkocdko 和想像中不一样,试了一下同源确实是可以直接调用。可能记忆中是对非同源的注入方式吧,印象中很麻烦
    daquandiao2
    daquandiao2
    Feb 9, 2021
    3
    非同源肯定不行啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1486 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 16:43 · PVG 00:43 · LAX 08:43 · JFK 11:43
    ♥ Do have faith in what you're doing.