How to get the html code from a web page (different domain)?

后端 未结 3 1274
无人共我
无人共我 2021-01-22 18:16

How can I create a javascript script that allows me to get the html code of a different page from a different domain and allows me to edit and display the code?? Thanks in advan

3条回答
  •  清歌不尽
    2021-01-22 19:03

    This isn't possible in the naive sense because you will get killed by javascript's same domain policy.

    Now if you have access to your own web server, you could set up a service that listens for your request which would include a 3rd party URL to fetch. Your service would pull the source for the 3rd party domain and return it as the response to your request. Then you take that response and append it into your editable field.

    EDIT: This answer seems to be the same principle as the YQL (Yahoo Query Language) answer that was posted as well.

提交回复
热议问题