1

Possible Duplicate:
Javascript or JQuery get html content from external site

I want JavaScript to get a web page, say the Google homepage, and retrieve its (obviously) HTML code. I have no idea of how to do it, mainly because I'm not really into JavaScript-ing. If possible, I'd use solutions which don't require libraries (eg jQuery) or light ones, due to speed issues.

Community
  • 1
  • 1
Giulio Muscarello
  • 1,312
  • 2
  • 12
  • 33

2 Answers2

0

You will only be able to get webpages that are on your own website. The browser will prevent you from loading any HTML from an external site. (Unless you use JSONP, but that would not let you load the HTML)

Mitch Dempsey
  • 38,725
  • 6
  • 68
  • 74
0

As Mitch correctly said, it is not possible for JavaScript to download HTML from an arbitrary web site.

I am not sure what your requirements are, but here are some ideas that can handle less general cases:

  1. If you want to load HTML from a page on a server that you control, then you can set CORS headers on the server, and then your JavaScript will be able to load from it (easily on modern browsers, and with some hacks on older browsers)
  2. If you just want to display HTML from the other web page, but not need to do any processing of it, then you can use an iframe to embed the the other web page in your page.
Eamonn O'Brien-Strain
  • 3,352
  • 1
  • 23
  • 33