0

I am trying to access iframe dom elements from rails 3 partial but its not as expected.

I am trying to access the iframe like this

$j("#batch_grid_frame").contents().find('#ship_box_id').html("HTML")

When i access the page from application it does not update the DOM. But when i run the same below code in browser console this works.

$j("#batch_grid_frame").contents().find('#ship_box_id').html("HTML")

After i googled and tried various things, this is working but is there some way in Jquery i can get this to work

var iframe = window.parent.document.getElementById('batch_grid_frame');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

innerDoc.getElementById("shipyu_ox_id").innerHTML = "<%= escape_javascript(render :partial => 'elements/box_select', :locals => {:ywo_types => @ywo_types}) %>";

Any help will be appreciated. Thanks.

opensource-developer
  • 2,826
  • 4
  • 38
  • 88

1 Answers1

0

Finally what helped me resolve the issue was the below answer how to access iFrame parent page using jquery?.

I updated my code to

$j("#batch_grid_frame",window.parent.document).contents().find('#ship_box_id').html("HTML")

and it worked. Thanks.

Community
  • 1
  • 1
opensource-developer
  • 2,826
  • 4
  • 38
  • 88