Using CSS to affect div style inside iframe

前端 未结 13 1757
失恋的感觉
失恋的感觉 2020-11-22 07:00

Is it possible to change styles of a div that resides inside an iframe on the page using CSS only?

13条回答
  •  庸人自扰
    2020-11-22 07:23

    You need JavaScript. It is the same as doing it in the parent page, except you must prefix your JavaScript command with the name of the iframe.

    Remember, the same origin policy applies, so you can only do this to an iframe element which is coming from your own server.

    I use the Prototype framework to make it easier:

    frame1.$('mydiv').style.border = '1px solid #000000'
    

    or

    frame1.$('mydiv').addClassName('withborder')
    

提交回复
热议问题