Is this possible? If so, how could I make it where you give it a URL, and it will return the page data (as in, the whole data, the <html>, everything). Specifically, I want to use this with javascript to edit the html and use the edited source in an iframe.
_player1537 wrote:
Is this possible? If so, how could I make it where you give it a URL, and it will return the page data (as in, the whole data, the <html>, everything). Specifically, I want to use this with javascript to edit the html and use the edited source in an iframe.
The simplest way to do this is with the file_get_contents() function, which works on URLs as well as local files:

http://us.php.net/file_get_contents

However, it often does not work under restricted webhosting, in which case you'll need to use the cURL library instead.
What would be the way to give the data this gets to javascript? Or would it be best to just edit the source using PHP?
_player1537 wrote:
What would be the way to give the data this gets to javascript? Or would it be best to just edit the source using PHP?
Well, you can directly read the page clientside with Javascript by using the XMLHttpRequest object (the core of most AJAX).
I tried to do the xmlHttprequest thing, but (and this is for jBOS) it didn't work >.<

I got this error:

Code:
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: file:///C:/Users/Tanner/Desktop/JBOS/apps/Test/Test.js :: Test_open :: line 5" data: no]


from this code:

Code:
function Test_open()
{
   var req = new XMLHttpRequest(); 
   req.open('GET', 'http://www.mozilla.org/', false);   
   req.send(null); 
   if(req.status == 200) 
      window_create("tawr",100,100,100,100,req.responseText);
}
So, it's *asynchronous, so you need to do something more like this:


Code:
function function handler() {
 if(this.readyState == 4 && this.status == 200) {
  // so far so good
  if(this.responseXML != null)
     // success!
     alert(this.responseXML);
  else
   test(null);
 } else if (this.readyState == 4 && this.status != 200) {
  // fetched the wrong page or network error...
  alert('OHNOFAIL');
 }
}

var client = new XMLHttpRequest();
client.onreadystatechange = handler;
client.open("GET", "unicorn.xml");
client.send();


Disclaimer: code more or less stolen from:

http://www.w3.org/TR/XMLHttpRequest/
You also can't do an XMLHttpRequest to another domain, it *must* be the same domain that the JavaScript is running from. So you'll need to bounce if off of the PHP server that is hosting the JS.
Kllrnohj wrote:
You also can't do an XMLHttpRequest to another domain, it *must* be the same domain that the JavaScript is running from. So you'll need to bounce if off of the PHP server that is hosting the JS.
Indeed, except that I think his object is local files from the local filesystem, which is acceptable. If it's something from another domain, you'll need to use a PHP grabber. The purpose of this is to avoid XSS eploits.
KermMartian wrote:
Indeed, except that I think his object is local files from the local filesystem, which is acceptable. If it's something from another domain, you'll need to use a PHP grabber. The purpose of this is to avoid XSS eploits.



Code:
req.open('GET', 'http://www.mozilla.org/', false);   


mozilla.org is located on his filesystem? News to me Razz
Well yeah, that part was just a test. Razz I suppose that's another reason why his example didn't work, but I was thinking of his eventual goal.
Impossible.
allynfolksjr wrote:
Impossible.
The fact that your hair is so ridiculous is impossible.
KermMartian wrote:
_player1537 wrote:
Is this possible? If so, how could I make it where you give it a URL, and it will return the page data (as in, the whole data, the <html>, everything). Specifically, I want to use this with javascript to edit the html and use the edited source in an iframe.
The simplest way to do this is with the file_get_contents() function, which works on URLs as well as local files:

http://us.php.net/file_get_contents

However, it often does not work under restricted webhosting, in which case you'll need to use the cURL library instead.
What if that is disabled too?
Then in that case, you're pretty much SOL. :/ You could do some manual socket manipulation, but if cURL is disabled, they probably went through the trouble to block that to.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement