create iframe to parse html from another html page?
<html>
<body>
<script type="text/javascript">
var req = new XMLHttpRequest();
req.open('GET', 'file://localhost/C:/Users/johan/mainMenu_2.html', false);
req.send(null);
if(req.status == 200)
dump(req.responseText);
var pageLinks = [];
var anchors = req.getElementsByTagName('a');
var numAnchors = anchors.length;
for(var i = 0; i < numAnchors; i++) {
//pageLinks.push(anchors[i].href);
document.write(anchors[i]);
}
</script>
</body>
</html>
With the access denied error on the 'GET' command
But I heard that you could get around this 'acces denied' error if you create an iframe and then read开发者_JAVA技巧 from that page. So how would you do this whitout using any server side languages?
file://localhost/C:/
is most definitely wrong.
Either use http://localhost
or file://C:/
If possible, use a local web server because access to file://
URLs is riddled with restrictions in most browsers.
You can also, use relative path to the current page (without the domain name) to make a request. If this is going to be hosted in two different domains, then browsers would not allow you to do what you are doing, due to security restriction.
If you would like to perform from cross domain communication, you can follow Secure Cross-Domain Communication in the Browser.
精彩评论