我的页面上有几个iframe(编辑器)。
如何找到要在哪个iframe中找到我当前选择的内容?
在这个编辑器中,我有有效的html上下文。这看起来像这样:
<iframe id="dynmaical_id">
<head>
...
</head>
<body>
<p>
<span>Text</span> //cursor is set somewhere here
</p>
</body>
<iframe>发布于 2012-03-15 08:56:49
您可以通过检查document.activeElement是否设置为它来确定当前选定内容是否在iframe内。然后,您可以使用document.activeElement.contentDocument.getSelection()来查找iframe中的选定内容。
https://stackoverflow.com/questions/3724740
复制相似问题