V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
LeeReamond
V2EX  ›  问与答

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

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

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

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

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

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