As you know, XMLHTTP is not allowed for requests in Cross Domain format for security reasons in Internet Explorer.
I have a WebBrowser control and I use DocumentText instead of Navigate for the URL. Since the current domain is about:blank , when the page tries to query itself or another domain, I get an Access is denied Javascript error.
Even if I use Navigate , if Javascript makes a request in a different domain, it does not work.
How can I get around this?
This HTML code should work with WebBrowser Control:
<body> <a href="javascript:getit('http://www.google.com')">this should work</a> <div id="x"></div> </body> <script> function XHConn() { var xmlhttp, bComplete = false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; }}} if (!xmlhttp) return null; this.connect = function(sURL, sMethod, sVars, fnDone) { if (!xmlhttp) return false; bComplete = false; sMethod = sMethod.toUpperCase(); try { if (sMethod == "GET") { xmlhttp.open(sMethod, sURL+"?"+sVars, true); sVars = ""; } else { xmlhttp.open(sMethod, sURL, true); xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4 && !bComplete) { bComplete = true; fnDone(xmlhttp); }}; xmlhttp.send(sVars); } catch(z) { return false; } return true; }; return this; } function getit(url){ var xmlhttp = new XHConn(); var fnWhenDone = function (oXML) { document.getElementById('x').innerHTML = oXML.responseText; alert(oXML.responseText); }; xmlhttp.connect(url, "GET", "", fnWhenDone); } </script>
source share