quantumdecipher Posted June 22, 2011 Share Posted June 22, 2011 I have a small project, which needs to read a status from an online page. Basically, I need a script to search for a certain tag ID from say www.foo.com/page1.html What I intend to do is get the ID of a certain tag and then save the inner HTML of it into a variable. Any ideas? I tried loading the page in an iFrame and trying JS to get an ID but fails. This is what i tried. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function getContentFromIframe(iFrameName) { var myIFrame = document.getElementById(iFrameName); var content = myIFrame.contentWindow.document.body.innerHTML; var status = content.getElementById('AREA:222_4'); alert(status); } </script> </head> <body> <iframe id="emap" src="http://emaplin3.foo.com/page1.html"> </iframe> <input type="button" value="Get Status" onclick="Javascript: getContentFromIframe('emap')" /> </body> </html> Now I'm lost. Link to comment https://forums.phpfreaks.com/topic/240101-script-to-read-an-online-pages-source-and-return-a-value-from-a-certain-id/ Share on other sites More sharing options...
Adam Posted June 22, 2011 Share Posted June 22, 2011 getElementById is a method of the document object. Should be: var content = myIFrame.contentWindow.document; Edit: although you might want to consider changing the name of the variable, as it's a little misleading now. Link to comment https://forums.phpfreaks.com/topic/240101-script-to-read-an-online-pages-source-and-return-a-value-from-a-certain-id/#findComment-1233343 Share on other sites More sharing options...
quantumdecipher Posted June 27, 2011 Author Share Posted June 27, 2011 Thanks for the Reply, but it still doesn't work. What I am trying to do is, say i got a page, index.html, then i got another page content.html. I have an iframe in index.html which contains content.html. i also have a button in index.html which when clicked needs to return an id from a tag inside content.html. I am trying to make a script which gets the innerHTML of a tag with the id provided by the user inside content.html. Link to comment https://forums.phpfreaks.com/topic/240101-script-to-read-an-online-pages-source-and-return-a-value-from-a-certain-id/#findComment-1235237 Share on other sites More sharing options...
Adam Posted June 27, 2011 Share Posted June 27, 2011 alert(status); Shouldn't that be status.innerHTML? Link to comment https://forums.phpfreaks.com/topic/240101-script-to-read-an-online-pages-source-and-return-a-value-from-a-certain-id/#findComment-1235297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.