I have an iFrame, content of which is inside another iFrame. I want to get the inside iFrame's src content. How can I do this using javascript?
-
Is what you're trying to do allowed by the same-origin rule?derobert– derobert2009-08-12 06:51:19 +00:00Commented Aug 12, 2009 at 6:51
-
what i am expecting is if i have an iframe inside another iframe then how can get the inner iframe's src?Paulraj– Paulraj2009-08-12 07:18:51 +00:00Commented Aug 12, 2009 at 7:18
-
Is the page in the inner iframe on the same host as your page?Gareth– Gareth2009-08-12 07:21:25 +00:00Commented Aug 12, 2009 at 7:21
-
yes. both the pages are in same host and same root.Paulraj– Paulraj2009-08-12 07:32:42 +00:00Commented Aug 12, 2009 at 7:32
-
1Are you asking for the value of the src attribute or the value of the contents of the page?Shane Tomlinson– Shane Tomlinson2009-08-12 19:11:52 +00:00Commented Aug 12, 2009 at 19:11
4 Answers
iframeInstance.contentWindow.document - this document loaded from SRC url. and vice verse - to get from inner document to parent use: parent.document
1 Comment
<body>
<div id="f1" style="padding-left:5px;">..</div>
<script type="text/javascript">
document.getElementById("f1").innerHTML = '<iframe src="frame.php or html" width="200" height="100" frameborder="0" scrolling="no"></iframe>';
</script>
</body>
</html>
I am not so expert but this for your script hints, you can modify and test for your pages.
Comments
In a desktop application special usecase there was a need to executeScript in the browser engine to fill out some inputs unattended by data base driven content..
step A) get the page src usually displayed as an iframe within another iframe
var newUrl = document.getElementById('iframeNestedFirst').contentWindow.document.getElementById('iframeExternalNestedWithinFirst').src;
step B) open that detected url including runtime tokens on a new page
window.open(newUrl).focus(); or window.open(newUrl,'_blank').focus();
Now you might get access to the DOM of that - as foreseen as an iframe - content of the different domain, when loaded as a new document.