7

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?

user965641
  • 137
  • 1
  • 1
  • 11
Paulraj
  • 3,373
  • 3
  • 36
  • 40

4 Answers4

5

The outer page:

<html>
<body>
<iframe id="ifr1" src="page1.htm"></iframe>
<iframe id="ifr2" src="http://www.google.com"></iframe>
</body>
</html>

page1.htm:

<html>
<body>
<script type="text/javascript">
document.write(parent.document.getElementById('ifr2').src);
</script>
</body>
</html>
Joshua
  • 1,913
  • 1
  • 19
  • 31
1
<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.

IshaniNet
  • 153
  • 10
1

iframeInstance.contentWindow.document - this document loaded from SRC url. and vice verse - to get from inner document to parent use: parent.document

Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • i got src of outer iframe. if i want the inner iframe src how can i get ? can u pls give me an example regarding my question ? thanks. – Paulraj Aug 12 '09 at 07:08
0

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.

Vanden
  • 1
  • 1