JavaScript - A Contentdocument.readystate Hack
I needed to know if a remote Page was completely loaded in an iframe.
If I try to use framename.contentDocument.readyState=='complete' I get an permissions error. However if a create a local Page such as: ----------------------------------------------- <html> <body> <iframe src="http//:somewhere.com" > </iframe> </body> </html> --------------------------------------- I can check whether the local Page, hence the remote Page I was interested in is loaded. Will this hack go away or does it conform to the standard? Similar TutorialsHi, see the following 2 parts of code (altered from http://w3schools.com/js/tryit.asp?fi...ontentdocument) Code: <body> <iframe src="hoi.htm" id="frame1"></iframe> <br /><br /> <script type="text/javascript"> function getText() { var x=document.getElementById("frame1").contentDocument; alert(x.forms); } </script> <input type="button" onclick="getText()" value="Get text" /> </body> Code: <body> <iframe src="http://web.qq.com/" id="qqwin" style="height:300px;"></iframe> <br /><br /> <script type="text/javascript"> function getDoc() { var y=window.document.getElementById('qqwin').contentDocument; alert(y.forms); } </script> <input type="button" onclick="getDoc()" value="Get doc" /> </body> hoi.htm is an existing empty document. the first part of code works, but as soon as I change the iframe source into http://www.qq.com or http://www.w3schools.com no alert is shown anymore. the contentDocument I get though: when I change Code: alert(y.forms); into Code: alert(y); , I get an alert saying object HTML document basically: when I use an empty test document as iframe source, I can get everything I want from the contentDocument, but when I use an external source I can only get the contentDocument itself as an object, but not anything thats in there my question is 'how do I get elements from an externally sourced contentDocument?' Kind regards, Klaas Hi. Just started fooling around with Ajax a bit back. So far, it's been fine. Today, though, I'm hitting some error I can't figure out. It *should* work, but it doesn't, and I have no idea why. Simple HTML form page with a bit of css. No big deal. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="text/javascript" src="livesearch.js"></script> <style type="text/css"> #livesearch { margin:0px; width:194px; } #txt1 { margin:0px; } </style> </head> <body> <form> <input type="text" id="txt1" size="30" onkeyup="showResult(this.value)" /> <div id="livesearch"></div> </form>type </body> </html> Problem area below in bold. Code: function showResult(str){ if (str.length == 0) { document.getElementById("livesearch").innerHTML = ""; document.getElementById("livesearch").style.border = "0px"; } var xmlhttp = getXMLHttpObject(); if (xmlhttp == null){ alert("Your browser does not support XML HTTP requests!"); return; } var url = "livesearch.php"; url = url + "?q=" + str; url = url + "&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged ; xmlhttp.open("GET", url, true); xmlhttp.send(null); } function stateChanged(){ if (xmlhttp.readyState == 4){ alert("Never seems to hit a readystate==4"); document.getElementById("livesearch").innerhtml = xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } } function getXMLHttpObject(){ //Current browsers if (window.XMLHttpRequest){ return new XMLHttpRequest(); } //For IE 5/6 if(window.ActiveXObject){ return new ActiveXObject("Microsoft.XMLHTTP"); } else { return null; } } My PHP file is just a simple echo statement to see that it works to that point. It doesn't. For whatever reason, it never seems to hit readyState ==4. It enters the function (I've checked with alerts), but the if statement never comes out to be true. I have no idea why. I've combed over the code for errors for a while now and I can't find anything. Any ideas? Would be much obliged. so my site ... www.brianapurserphotography.com/kitchen1/ (click portfolio to see the div im referring too) loads fine in firefox and safari on my mac but.... refuses to scroll in IE so to find out tonight. The scroll bar comes up just fine but the actual scroll bar itself that one uses to drag does not. All that shows is an inactive scroll bar with inactive arrows. Why? Hey, hoping someone can help. As this is my first post and I have a very very very small understanding of Javascript you have permission to mock me! Anyway, here goes... I am using a third party shopping cart system. One of the dropdown menus uses an array as the 'name'. <select name="product[]"> I'm pretty sure it has to stay this way or the cart won't work. I have a function which runs to make sure it can't be left on the first option when submitted, however it won't work with the 'name' containing square brackets! function validate_form_acflgotmt ( ) { valid = true; if ( document.acftshirt.product[].selectedIndex == 0 ) { alert ( "Neigh! Whoa boy, don't forget to choose a t-shirt size!" ); valid = false; } return valid; } If anyone can help please do and I will shed a single tear of joy. Thanks! Jake |