I want to implement the following things by using JavaScript:
- usin开发者_开发知识库g AJAX to get a page source;
- put in some data into this page source;
- show the changed page to users.
So it is possible? If so, how?
By the way, I cannot use server side technologies. And if JS is not suitable for it, what client technologies can be used in this case?
Assuming that the page you are wanting to get source from is on the same domain, you can get the page source like this:
if("XMLHttpRequest" in window){
xmlhttp=new XMLHttpRequest();
}
if("ActiveXObject" in window){
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
xmlhttp.open('GET', "URLofFileYouWantToGetTheSourceFrom", true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.responseText);
}
};
xmlhttp.send(null);
精彩评论