Selector for element inside a frame (with same origin)

我是研究僧i 提交于 2019-12-19 06:32:40

问题


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()


来源:https://stackoverflow.com/questions/6473557/selector-for-element-inside-a-frame-with-same-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!