2

I need to edit an iframe with jQuery but I'm unable to do it.

I tried with:

$(document).ready(function(){
    $("#iframe").on('load',function(){
        $(this).contents().find('body').html('a');
    });
});

This code doesn't work.

EDIT

The iframe is related to a different domain.

NineCattoRules
  • 2,253
  • 6
  • 39
  • 84

1 Answers1

1

You just answered your own question. Your code doesn't work because of the Same Origin Policy.

You can use a PHP proxy to bypass this restriction.

<?php
    $url = "http://example.com";
    $domain = file_get_contents($url);
    echo $domain;
?>

And then use that information in your script.

This question has more details about this issue.

Hope this helps!

Community
  • 1
  • 1
  • But doesn't it break the layout when the target page has non-absolute URLs and relative links? – Mori Nov 29 '13 at 06:53