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

后端 未结 3 1271
无人共我
无人共我 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 18:52

    Have a look at Cross-domain requests with jQuery (GitHub repo).

    0 讨论(0)
  • 2021-01-22 19:02

    You can't. Cross domain scripting is not possible... you can also search SO and find many answers to this question.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题