Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're using a library like jQuery then you could simply use the <code>load()</code> function which gets the code of a webpage (or a partial of a webpage if you append a <code>#myDiv</code> to the URL). You could then handle that information if you put it in a variable. If you're just using Javascript then you'd need to look into making an AJAX request (which is what <code>load()</code> does). You can find more information on how to do this <a href="https://stackoverflow.com/questions/8197709/javascript-read-html-from-url-into-string">located here</a>.</p> <p>For more information on the <code>load()</code> function, <a href="http://api.jquery.com/load/" rel="nofollow noreferrer">read jQuery's documentation</a>.</p> <p>Keep in mind, jQuery's <code>load()</code> function is for loading HTML into an element. If you want to read and manipulate that data then you should probably use the <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer"><code>ajax()</code> function</a>. This way you could do something like the following:</p> <pre><code>$.ajax({ type: 'get', url: 'http://www.google.com', crossDomain: true, //Very important, ensures you can get data from a domain that isn't your own! success: function(data) { $('#myDiv').html(data); //Now I can handle all the HTML from my URL from a &lt;div&gt; tag called #myDiv, the following will alert out the body of http://www.google.com alert($('#myDiv').find('body')); } }); </code></pre> <p>This will essentially make a <strong>GET</strong> request to the specified URL, while noting that it is not of the same domain name as the request's origin (your server) and then handles the success in a function with the HTML returned in a variable <code>data</code>. You can use data however you please now seeing as it's your variable now, including parsing of that information how you please.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload