0

I got a question regarding checking if objects are visible within the iframe. Is that even possible? So the situation would be I check from outside the IFRAME if an object is visible within the Iframe.

This is not the same situation as the solution [here] (Determine if an element in an iframe is visible on the screen) due to the fact that I can not modify the IFRAME, therefore I could not use their solution

HTML Code

<iframe src="http://www.w3schools.com">
  <p>Your browser does not support iframes.</p>
</iframe>

JS CODE

var check = $('.w3-container top').is(":visible"); 
alert(check);

The alert will always give the value "false".

JSFIDDLE (watch it in Firefox otherwise the iframe does not work)

Community
  • 1
  • 1
Rotan075
  • 2,567
  • 5
  • 32
  • 54
  • "Is that even possible?". Only if the iframe is served from the same domain otherwise Same origin policy doesn't allow this. – Ram Sep 17 '15 at 12:00
  • @D4V1D no that is not a duplicate due to the fact that I can not modify the iframe html code. Look at my updated question. – Rotan075 Sep 17 '15 at 12:00
  • @Vohuman I know, I want to use it locally but I could not really give a JSFIDDLE of my local stuff;) – Rotan075 Sep 17 '15 at 12:01

1 Answers1

2

First things first, you should wait until the iframe is loaded via load event.But,it will not work this way, you are on different domain than www.w3schools.com, so you won't be able to access the child iframe DOM model.

xxxmatko
  • 4,017
  • 2
  • 17
  • 24
  • I edited your jsfiddle [here](http://jsfiddle.net/32Lvjg5o/1/), you will see that yout selector didn't select anything, that is why you see always false. – xxxmatko Sep 17 '15 at 12:02
  • Yeah I know ;) But would it work if I load my page within the same domain as where my iframe is pointing to? – Rotan075 Sep 17 '15 at 12:03
  • On the same domain you could access child window and its properties and also from child window you can access parent window properties. – xxxmatko Sep 17 '15 at 18:01