Selector for element inside a frame (with same ori

2019-02-17 00:38发布

问题:

I have a webpage with the following structure:

<html>
<head>...</head>
<frameset>
<frame name="frame1" src="/index.jsp"/>
<frame name="frame2" src="/blank.jsp"/>
</frameset>
</html>

index.jsp contains:

<html>
<head>...</head>
<body>
... <div id="test">test is here</div> ...
</body>
</html>

I need a jQuery selector to directly access div#test. So far I've only been able to write it like this: $(frames[0].document.body) ...or this: $("frame[name='frame1']"). But I have a template which requires me to write my selector inside $("here only"). So I can't use .find() or other functions.

回答1:

Try:

$("div#test", $("#someIFrame").contents())


回答2:

yeah I got it. thanks.

This is what I wrote.

$("div[id='test'] > span",frames['frame1'].document).text()