开发者

By using JS, it is possible to get a page source, and then respond users with this getting page

I want to implement the following things by using JavaScript:

  1. usin开发者_开发知识库g AJAX to get a page source;
  2. put in some data into this page source;
  3. 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜