I have a jsp page page1.jsp and an iFrame inside it 'id=iFrame1' and I'm having another page page2.jsp that is loading inside iFrame1. I need to access the iFrame1 properties at the page load of page2.jsp. How can we access it using javascript/jQuery? Can anyone please help.
Asked
Active
Viewed 137 times
0
-
1Hello, please take a time to go through the [welcome tour](https://stackoverflow.com/tour) to know your way around here , read how to create a [mcve] example and also check [ask] so you increase your chances to get feedback and useful answers. – garfbradaz Jul 26 '17 at 06:21
-
Possible duplicate of [jQuery/JavaScript: accessing contents of an iframe](https://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) – Jorge Fuentes González Jul 26 '17 at 06:21
-
Possible duplicate of [how to access iFrame parent page using jquery?](https://stackoverflow.com/questions/726816/how-to-access-iframe-parent-page-using-jquery) – david25272 Jul 26 '17 at 06:24
2 Answers
0
Try some formatting for your next question, it's really hard to read you.
$(document).ready(function(){
var iFrameDOM = $("iframe#frameID").contents();
iFrameDOM.find(".page").css("background-color", "#fff");
});
Also the search function would have answered this almost immediately.

チャールズ
- 123
- 1
- 7
0
In page2.jsp use can use this code to get iFrame1 element:
window.parent.parent.document.getElementById('iFrame1')
So, if you would like to access its property src
you can use:
window.parent.parent.document.getElementById('iFrame1').src
Also,
var $f2 = window.parent.parent.document.getElementById('iFrame1');
$f2.css('border','solid 5px red');

Amit Bhagat
- 4,182
- 3
- 23
- 24