[removed] how to fetch the content of a web page

前端 未结 4 1983
傲寒
傲寒 2021-02-06 07:38

In JS is it possible to fetch the content of a web page assigning it to a variable? For example, why the following toy code does not work?

var req = new XMLHttp         


        
4条回答
  •  猫巷女王i
    2021-02-06 08:20

    If you really need to do this, you can try using jQuery and iFrames (read more at (read more http://softwareas.com/cross-domain-communication-with-iframes).

    Also, you can try with Access-Control-Allow-Origin: http://yourdomain:1234/ in headers, google for Cross-Origin Resource Sharing. It's relativelly new though, not all browsers know about this. That also depends if you have the control of the other server headers generation and few other things.

提交回复
热议问题