tendouser Posted October 7, 2011 Share Posted October 7, 2011 How can I access with javascript an iframe DOM elements? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/ Share on other sites More sharing options...
tendouser Posted October 7, 2011 Author Share Posted October 7, 2011 Ok! It's for Google Chrome this issue. Safari, IE, FF, Opera work fine. <!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> <title>J</title> <script type="text/javascript"> function changeStyle() { var x=document.getElementById("myframe"); var y=(x.contentWindow || x.contentDocument); if (y.document) y=y.document; y.body.style.backgroundColor="#0000ff"; } </script> </head> <body onload="changeStyle()"> <iframe id="myframe" src="js1.htm"> <p>Your browser does not support iframes.</p> </iframe> <br /><br /> <input type="button" onclick="changeStyle()" value="Change background color" /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/#findComment-1277090 Share on other sites More sharing options...
requinix Posted October 7, 2011 Share Posted October 7, 2011 Works for me. You know that Chrome will block access to the iframe if you aren't viewing the files through a web server? Check the error console. Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/#findComment-1277092 Share on other sites More sharing options...
tendouser Posted October 7, 2011 Author Share Posted October 7, 2011 I have both files in my PC. The console outputs Unsafe JavaScript attempt to access frame with URL file:///C:/Documents%20and%20Settings/Administrador/Escritorio/js1.htm from frame with URL file:///C:/Documents%20and%20Settings/Administrador/Escritorio/js2.htm. Domains, protocols and ports must match. Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/#findComment-1277103 Share on other sites More sharing options...
requinix Posted October 7, 2011 Share Posted October 7, 2011 It's a known bug (aka "security feature"). I think there's an option to disable it but I don't remember what. WAMP is easy to install... Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/#findComment-1277113 Share on other sites More sharing options...
tendouser Posted October 10, 2011 Author Share Posted October 10, 2011 One more question about this issue. Does contentDocument() javascript method work on subdomains. I have this site http://www.binal.ac.pa/harias/series.htm and I load an iframe in each of this categories listed. What I want to do with JS is to send a char via simulating a click and sending the char to the DB application. Thanks for your comments! And yes I'm using Chrome but now with Wamp localhost. Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/#findComment-1277804 Share on other sites More sharing options...
tendouser Posted October 10, 2011 Author Share Posted October 10, 2011 Sorry I forgot to mention the database app and data is in this subdomain: http://bdigital.binal.ac.pa Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/#findComment-1277806 Share on other sites More sharing options...
tendouser Posted October 11, 2011 Author Share Posted October 11, 2011 Ok I did it. It doesn't work with a subdomain. Quote Link to comment https://forums.phpfreaks.com/topic/248656-iframe-content/#findComment-1278380 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.