-2

Suppose in other website exists a div element with a table in it. The content of div element changes during the time. I want to show that div element and it's contents in my website. Is it possible using Asp or jquery or javascript or other ways? I have heard about socket programming.

EDIT:
I don't want whole webpage. just a part of it.I think Iframe can't help me.

Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99
Raymond Morphy
  • 2,464
  • 9
  • 51
  • 93
  • Create a server side script which actually access the above said web page. In PHP we can use Curl and in Python urllib2. Write a Ajax function which calls this script. We may have to write a parser since the script will be garbing the entire page. Get required div and format as you wish return it as the reply to Ajax – Nick Jan 22 '13 at 10:15
  • Or will this http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/ for you ? – Nick Jan 22 '13 at 10:21

1 Answers1

2

With plain JS/Browser programming, use iframes since:

  • AJAX cannot do cross-domain unless the remote server supports Cross-Origin Resource Sharing (CORS) which usually does not.
  • Sockets, JSON or JSONP need some server logic to interface with your code, which I highly doubt is implemented on the remote server.

So unless you control the remote server where you can implement logic or allow CORS, there's little you can do about it.

OR...

If you have access to your server, you can have your server act as a proxy and read the remote page for you. The server is not bound to the Same Origin Policy (SOP) thus can read remote pages. And with this, you can use AJAX requests your server.

It runs like

Your browser <-AJAX-> your server <-wget/curl/fopen/whatever-> remote server

And the request url to your server typically looks like (unencoded):

http://mysite.com/remoteread.php?remote_url=http://myremotesite.com/thispage.php

then remoteread.php reads the remote page, and simply "relays" the reply to your browser.

Found a article from Yahoo that explains the methodology in more detail

Joseph
  • 117,725
  • 30
  • 181
  • 234
  • Could you send me an article or a link to explain me more details? – Raymond Morphy Jan 22 '13 at 10:19
  • It's basically common knowledge, so it just came from the top of my head. But the more general topic is titled ["Bypassing the Same Origin Policy"](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Joseph Jan 22 '13 at 10:35