How to completely copy the elements within an iframe and present them outside the iframe?

I know our needs are strange, but they do exist.

We will open a specified page in an iframe within a web page, then copy a specified element, take it outside the iframe, and ask for a perfect representation of it. For example, if the background color defined in a div, is red, it should also be red when it is taken outside. (note that the style definition of head benefit in iframe cannot be copied to the outside)

I think the crux of the problem is to find out exactly what css definitions are in that div, in iframe, and then assign values to the outside div. But I don"t know how to find a css definition of an element.

I hope all of you can help me.

Mar.07,2021

1, copy all runtime styles to the inline style of the new element document.defaultView.getComputedStyle (element, ""). CssText; ), but there is no way for pseudo elements and animation
2. Extract all the corresponding style definitions and copy them to the outside, you need to find them in this document.styleSheets . The advantage is that pseudo elements work correctly, but the animation needs to write something to copy it completely, and it seems that the new chrome does not allow external styles to be traversed from here, so this may also be incomplete

.
Menu