0

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.

knbibin
  • 497
  • 3
  • 11
  • 24
  • 1
    Hello, 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 Answers2

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.

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
  • 3,672
  • 2
  • 20
  • 21