0

I want to load content of an external webpage. I don't want to use an iframe because I need to style it as well.

Now i have:

$(".tweetPage")
            .html('<object class="webPage" id="tweetPage" data="http://www.somepage.com/example"/>');

Which drops a #document in my dom with head and body. This is close to what i want, I only want the content of the body.

Is this possible in some way?

clankill3r
  • 9,146
  • 20
  • 70
  • 126

1 Answers1

0

This way probably will not work. here there is a similar debate. jQuery load body from external HTML

I could to do using "WebRequest" to get the contents of the body. I used C #. You can adapt the code for your platform.

public string getBody(string urlAddress)
    {

        string data = string.Empty;

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        if (response.StatusCode == HttpStatusCode.OK)
        {
            Stream receiveStream = response.GetResponseStream();
            StreamReader readStream = null;
            if (response.CharacterSet == null)
                readStream = new StreamReader(receiveStream);
            else
                readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
            data = readStream.ReadToEnd();
            response.Close();
            readStream.Close();

            int ini = 0;
            int final = 0;

            ini = data.IndexOf("<body");
            final = data.IndexOf("</body>");

            return data.Substring(ini, final - ini + "</body>".Length);
        }


        return "Error";

    }
Community
  • 1
  • 1
Everson Rafael
  • 2,043
  • 2
  • 20
  • 20