Hello My script fetches the image from a given url and displays it in another page. newElement = document.createElement('div'); newElement.innerHTML = '<img src="http://www.adomain.com/myimage.gif" />'; thisElement.insertBefore(newElement, thisElement.childNode); PHP: Now instead of the image,i want to fetch the text in that page using its ID How can i modify this script to do it.. Please help. Regards, Sandeep
Never tried it myself as I use php for stuff like this. Some quick google'ing pulls up this tutorial: http://www.javascriptkit.com/dhtmltutors/ajaxincludes.shtml
you would need to use php regex I can attempt to code it just givce me a page that you want to get the text from. -john
i don't know if this would help but you could set a iframe with the id in the url like this: <iframe src="http://www.abc.net.au/news/default.htm#headlines" width="500px" height="50px" frameborder="0" scrolling="no"></iframe> Code (markup): the main topics section has an id called headlines, so i used an iframe to only show this section so i can put it on my website. All you have to do is change the iframe's width, height and the source URL. Original URL: http://www.abc.net.au/news/default.htm
that's not strictly true. javascript does have restrictions on accessing anything cross-domain through request/ajax/XHR, yes. but you can use JSONP to fetch JSON data from other domains in pure javascript. you can also use COMET to embed javascript through push on remote hosts. to do what you ask, its a simple ajax setup - you need to code a local php file that fetches a url through curl (or fopen if allowed) and outputs it. your javascript can then reference your local file instead as a proxy. for example: // javascript fetching the js and setting it into something called "output" // this is in mootools but use whatever ajax framework you fancy new Request({ url: "url_fetch.php", onComplete: function() { $("output").set("html", this.response.text); } }).send("url=http://www.foobar.com/about.php"); PHP: the php would look something like this: <? // url_fetch.php function fetchURL($what) { // code the fetch through curl or fopen. ... return $data; } echo fetchURL($_GET['url']); ?> PHP: you can apply additional formatting through the php, remove things like header, footer etc and extract only relevant data. also - keep in mind that relying on fetching this in real time will cause a severe CPU and network delay, especially so on larger sites. i would consider sending the fetch script to a cron job that runs say every 5 mins and serving the last fetched text from a database. good luck