Div over iframe that is from iframe itself

2020-03-26 07:12发布

I have a div that is contain inside an iframe from a external html

<iframe src="test.html">

The html based "context menu" need to be on top of the iframe but the html code of the context menu is in the iframe itself. A pure CSS solution is preferred.

标签: html css iframe
3条回答
我欲成王,谁敢阻挡
2楼-- · 2020-03-26 07:25

As long as both frames are in the same domain, you could use Javascript to move the DOM element to the parent frame (window.parent.document.appendChild(...)). I have done this and it works. It's just a lot of hassle and you must decide yourself whether it's worth it.

Be sure to check out bobince's comment on the issue below on how to do it.

Don't forget the child frame's style sheets don't apply to the menu once you move it to the parent.

查看更多
够拽才男人
3楼-- · 2020-03-26 07:26

Your really duplicating typical "Ajax" functionality, since its already been abstracted by many frameworks (like jQuery), and you are not likely to do it any better I'd give that a shot. Don't reinvent the wheel.

You can find a great example here.

$("#links").load("/Main_Page #jq-p-Getting-Started li");
查看更多
Luminary・发光体
4楼-- · 2020-03-26 07:36

The contents of an iframe cannot be displayed outside of the iframe. Within the iframe, you can have the div appear over other elements using "position: absolute" and "z-index: 1000" (or another appropriately large number). Note that absolutely positioned elements are removed from the flow of the document. The position can be set using the "top", "left", "right", and "bottom" CSS properties.

查看更多
登录 后发表回答