Note that there are some explanatory texts on larger screens.

plurals
  1. POSafely parse/work with HTML from XMLHttpRequest
    primarykey
    data
    text
    <p>I'm writing code (right now it's a Chrome extension, though I may make it cross-browser, or try to get the site owners to include the enhancement) that works with the contents of a particular <code>&lt;div&gt;</code> on a webpage that the user is viewing, and any pages that are part of the same discussion thread. So I find links to the other pages of the thread, and get them with <code>XMLHttpRequest</code>. What I want to do is just be able to use <code>.getElementsByClassName('foo')</code> on the resulting page. </p> <p>I know I can do that by loading the results of the request into a div (i.e. <a href="https://stackoverflow.com/questions/7677340/optimal-way-to-extract-a-url-from-web-page-loaded-via-xmlhttprequest">Optimal way to extract a URL from web page loaded via XMLHTTPRequest?</a>). However, while figuring out the best way to do this, I read that there are security concerns (<a href="https://developer.mozilla.org/En/Using_XMLHttpRequest#Analyzing_and_manipulating_HTML_responseText" rel="nofollow noreferrer">MDN - Safely Parsing Simple HTML to DOM</a>).</p> <p>In this case, I'm not sure that matters much, since the extension would just load a page from the same comment thread that the user was already looking at, but I'd still like to do this the right way. </p> <p>So what's the right way to work with HTML from an <code>XMLHttpRequest</code>? </p> <p>P.S. If the best answer is jQuery, then tell me that, but I've yet to start using jQuery, and would also like to know the fundamentals here. </p> <p>Edit: I don't know why I phrased things the way I did, but let me be clearer that I'm really hoping for a non-JQuery answer. I've been trying to learn the basics of javascript before learning JQuery and I'd prefer not to import a whole framework to call one function when I don't understand what I'm doing. That may seem irrational, but it's what I'm doing for the moment. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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