0

What I have is an iframe displaying a web page for a sensor that hosts it's own webpage showing humidity and temperature. All I really need is the current temperature and humidity so that I can display it on a main page displaying lab status. So from what I gather I need to reach into the iframe, that way I can get to the tr/td values for the table being used to hold what I need.

From scouring the internet top to bottom I put together the following code...

var myIFrame = document.getElementById('ifOmega');
var content = myIFrame.contentWindow.document.body.innerHTML;

The problem is that the second line silently fails. I tested myIframe to ensure that it executed and was not null. I am using Visual Studios 2010 and so I am not sure if maybe it's a limitation there? I only say that because when I try to type...

var content = myIFrame.

...the intellisense doesn't pop up with contentWindow as an option.

Even when I figure this out I'm not sure how to dig deeper other than.

var var0 = content.getElementById('rd0');

Where rd0 is the name/id of the cell that has a div inside containing the temperature value. I am assuming to reach into the I will need one of the javascript sibling/child methods?

BTW, my javascript is executed client side with...

Sys.Application.add_load(getTempTable);

..at the top.

Thank you for any help.

MethodMan
  • 18,625
  • 6
  • 34
  • 52
JoeManiaci
  • 435
  • 3
  • 15
  • How about ? http://stackoverflow.com/questions/1451208/access-iframe-elements-in-javascript – Aristos Jan 20 '15 at 18:08
  • And http://stackoverflow.com/questions/19498725/control-iframe-content-with-javascript-html – Aristos Jan 20 '15 at 18:08
  • @Aristos: 1st one I already tried and it also silently failed. 2nd one I didn't come across but that looks promising. EDIT: 2nd one also silently dies. – JoeManiaci Jan 20 '15 at 18:10
  • Maybe it being client-side is the problem? Maybe my script is being ran before the external page is being rendered? Therefore 'lb0' doesn't yet exist, but the asp.net control-> iframe does. – JoeManiaci Jan 20 '15 at 18:22
  • You have check that the ids are correct ? eg asp.net usually change the ids, and we use the ClientID property to gets them like: `getElementById('<%=myIFrameElemId.ClientID%>')` – Aristos Jan 20 '15 at 18:23
  • Well I guess I should have googled how best to troubleshoot javascript in visual studios. I started debugging in IE and learned to enable script debugging and now I see why all the different techniques were dying. I got an Access is Denied error. – JoeManiaci Jan 20 '15 at 18:29

0 Answers0