2

According to this answer:

Invoking JavaScript code in an iframe from the parent page

I have an iframe that loads a page that has a div with the id flash_container

<iframe src="http://www.remote.com/a.html" id="iframeID">

I placed this code on my parent page (the page that loads the iframe) but it doesn't seem to work:

document.getElementById('iframeID').contentWindow.targetFunction();
function targetFunction() {
    var el = document.getElementById('flash_container');
    el.style.zoom = 0.7;
    el.style.MozTransform = 'scale(0.7)';
    el.style.WebkitTransform = 'scale(0.7)';
}

What I'm trying to do is to zoom-out the inner page inside the iframe from the parent page.

Community
  • 1
  • 1
Or Weinberger
  • 7,332
  • 23
  • 71
  • 116

2 Answers2

2

It's impossible to say for certain what's wrong, but I have some ideas you might want to look into.

  1. Make sure that the iframe is loaded. Trying to do something inside a frame that hasn't finished loading clearly won't work
  2. Are you sure that you don't have cross-domain problems. You cannot manipulate the contents of a cross-domain iframe.
zatatatata
  • 4,761
  • 1
  • 20
  • 41
  • Probably no. 2, It's not in the same domain. Nothing I can do? – Or Weinberger Jul 18 '11 at 14:30
  • 2
    Sadly (luckily for the average user, actually), theres nothing you can do about it with javascript. You could proxy the request via your own web server that pulls the site using PHP etc and then prints it out on the same domain. This would enable iframe embedding of sites on other domains. This, however, causes other problems, for example if the target site tries to use AJAX, it would generate a cross-domain error and fail. – zatatatata Jul 18 '11 at 14:37
0

Actually you could, if both side (your page and the page in the iframe) agree on sharing information, you could use message passsing. See https://stackoverflow.com/a/7938270/1571709

Community
  • 1
  • 1
Dominique Fortin
  • 2,212
  • 15
  • 20