admin管理员组

文章数量:1389762

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 advance.

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 advance.

Share Improve this question asked Jul 28, 2011 at 2:59 Akhil ReddyAkhil Reddy 2577 silver badges17 bronze badges 4
  • what do you mean by ' allows me to edit and display the code' ? – Jayantha Lal Sirisena Commented Jul 28, 2011 at 3:02
  • 1 I want to be able to parse the html and change it a little – Akhil Reddy Commented Jul 28, 2011 at 3:04
  • 2 It can be done with a CGI/Perl script on your server and then retrieved by your page to be manipulated with JavaScript. Not posting as an answer since you're not asking about CGI or Perl although it will ultimately get you to the same place. – Sparky Commented Jul 28, 2011 at 3:26
  • possible duplicate of Adapt ajax for crossdomain – Quentin Commented Feb 14, 2012 at 15:34
Add a ment  | 

3 Answers 3

Reset to default 4

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

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.

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

本文标签: javascriptHow to get the html code from a web page (different domain)Stack Overflow