在Iframe中搜索特定的标记,然后创建另一个Iframe

Search inside Iframe for a specific tag and create another iframe

本文关键字:Iframe 然后 创建 另一个 搜索      更新时间:2023-09-26

我有以下代码:

<FORM target="frame" onsubmit="document.getElementById('frame').style.display = 'block';" method="post" action="http://www.example.com/index.html">
<input type="text" autocomplete="off" value="" name="search-field" id="header-search-field">
<button type="submit">Search</button></FORM>
<iframe width="700" height="700" id="frame" name="frame" style="display: none;"></iframe>

Iframe在提交表单时显示正确。现在我必须创建第二个Iframe,它在之前加载的内容中搜索特定的标签,并且只有在找到时才显示。我必须搜索一个特定的标签:

<table id="item_specification" cellspacing="0" cellpadding="0"> with all the content inside </table>

并且只显示表ID内的内容(也有表)

如果您没有违反跨来源策略,您可以通过以下方式访问iframe文档:

document.getElementById('header-search-field').contentDocument