PDA

View Full Version : access iframe content



mlybarger
18 Jun 2014, 6:30 AM
i'm new to extjs. i have an iframe loading some content from the same context. as such:

{
xtype: 'box',
id: 'abcIframe',
autoEl : {
tag : "iframe",
src: "abc.jsp",
style: 'width: 100%; border: none'
}
}


later i have a button, and in i'd like to get access to the iframe document and elements in my javascript. any help is most appreciated.

thanks,
-mark-

Gary Schlosberg
18 Jun 2014, 6:42 AM
My understanding is that browser security prevents one from accessing an iframe from the parent. I believe you can access from iframe to parent so perhaps you can run code in the iframe and send info back.

mlybarger
18 Jun 2014, 8:42 AM
browser security doesn't affect this. it's on the same domain.

index.html


<html>
<head>
<title>TODO supply a title</title>
<script>
function clicked() {
var iframe = document.getElementById('subFrame');
var c = iframe.contentDocument.getElementById('newContent');
alert('c:'+ c.textContent);
}
</script>
</head>
<body>
<div id="mainContent">TODO main content</div>
<iframe id="subFrame" src="newhtml.html"></iframe>
<div id="clickMe" onclick="clicked()">CLICK ME</div>
</body>
</html>


newhtml.html



<html>
<head>
<title></title>
</head>
<body>
<div id="newContent">TODO sub content</div>
</body>
</html>

mlybarger
19 Jun 2014, 5:31 AM
found an answer:


var frame = Ext.getCmp('resumableIframe');
// then content can be accessed via...
var list = frame.el.dom.contentDocument.getElementsByClassName('resumable-file-name');