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?
Asked
Active
Viewed 5.0k times
7
user965641
- 127
- 1
- 1
- 11
Paulraj
- 3,325
- 3
- 36
- 39
-
Is what you're trying to do allowed by the same-origin rule? – derobert Aug 12 '09 at 06:51
-
what i am expecting is if i have an iframe inside another iframe then how can get the inner iframe's src? – Paulraj Aug 12 '09 at 07:18
-
Is the page in the inner iframe on the same host as your page? – Gareth Aug 12 '09 at 07:21
-
yes. both the pages are in same host and same root. – Paulraj Aug 12 '09 at 07:32
-
Are you asking for the value of the src attribute or the value of the contents of the page? – Shane Tomlinson Aug 12 '09 at 19:11
-
only the value of the iframe content. – Paulraj Aug 13 '09 at 05:16
3 Answers
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,883
- 1
- 18
- 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
- 133
- 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
- 22,648
- 12
- 68
- 116
-
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