Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Oh man. This is where we get into crazy land.</p> <p>As it stands, the key difference between jsdom and "the browser" is we can access the window externally. For instance in your example you set <code>$</code> to <code>window.$</code>, which is basically saying "hey, for this current window I want a reference to the jquery object". You could have 10's of windows, and hold references to all of their <code>$</code>'s.</p> <p>Now, lets say you load a new page due to a form submission/link click...</p> <p>JSDOM would need to reload the window and update the javascript context (potentially injecting the scripts you provided in the original jsdom.env call). Unfortunately, the reference(s) you held from the last window would be gone/overwritten. In other words, calling <code>$(...)</code> after the page had reloaded would result in unexpected behavior (most likely a memory leak or selection of dom elements on the previous page)</p> <p><strong>How do you get around this?</strong></p> <p>Since you are using jquery already, do something like..</p> <pre><code>var form = $('#htlbotForm'); var data = form.serialize(); var url = form.attr('action') || 'get'; var type = form.attr('enctype') || 'application/x-www-form-urlencoded'; var method = form.attr('method'); request({ url : url, method : method.toUpperCase(), body : data, headers : { 'Content-type' : type } },function(error, response, body) { // this assumes no error for brevity. var newDoc = jsdom.env(body, [/* scripts */], function(errors, window) { // do your post processing }); }); </code></pre> <p>YMMV, but this approach should work in non-ajax situations.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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