dizzy1 Posted August 26, 2011 Share Posted August 26, 2011 I'm trying to get the content of a iFrame the content will only ever be a single number, I've tried this: <script type="text/javascript"> function GetIframe() { var MyIFrameID = document.getElementById('MYIFRAME'); alert(MyIFrameID); } </script> <iframe id="MYIFRAME" src="www.MYEXAMPLEPAGE.COM?Food=1&Drink=2" ></iframe> <button type="button" onclick="GetIframe();">Show </button> But the alert message displays: [object HTMLFrameElement] Quote Link to comment https://forums.phpfreaks.com/topic/245778-reading-an-html-iframe-using-javascript/ Share on other sites More sharing options...
AyKay47 Posted August 26, 2011 Share Posted August 26, 2011 include this in your function// var iframe = document.getElementById(iFrameName); var content =iframe.contentWindow.document.body.innerHTML; Quote Link to comment https://forums.phpfreaks.com/topic/245778-reading-an-html-iframe-using-javascript/#findComment-1262364 Share on other sites More sharing options...
dizzy1 Posted August 26, 2011 Author Share Posted August 26, 2011 I tried that and I get an error displayed in Firebug which says: Permission denied for <www.MYEXAMPLEPAGE.COM> to get property Window.document Quote Link to comment https://forums.phpfreaks.com/topic/245778-reading-an-html-iframe-using-javascript/#findComment-1262378 Share on other sites More sharing options...
nogray Posted August 26, 2011 Share Posted August 26, 2011 You can read other domains content using javascript for security reasons. You would need to create a proxy on your domain and request the url through that proxy. Quote Link to comment https://forums.phpfreaks.com/topic/245778-reading-an-html-iframe-using-javascript/#findComment-1262381 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.