Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate new window using jquery
    primarykey
    data
    text
    <p>I'm working on a little project in JavaScript/jQuery. </p> <p>In order to display results from a calculation done in javascript, I'd like to open a new window with some predefined content and modify this content in order to display the results: Im using code like this:</p> <pre><code>var resultwindow = window.open('result.html') var doc = $('body', resultwindow.document); doc.append("&lt;p&gt;Result&lt;/p&gt;") </code></pre> <p>This is not working since the result document is not yet loaded when I append the content, so it is overwritten with the contents of 'result.html'.</p> <p>I also tried</p> <pre><code>$(resultwindow.document).ready(function() { // ... Fill result document here }) </code></pre> <p>and</p> <pre><code>$(resultwindow.document).load(function() { // ... Fill result document here }) </code></pre> <p>but <code>ready()</code> works only on the current document (it is called immediately, if the current document is already loaded), and <code>load</code> doesn't get called at all.</p> <p>Perhaps someone can point me to the right direction. Thanks in advance!</p> <p><strong>EDIT</strong>:</p> <p>I finally solved this by creating the new document "by hand" in Javascript like:</p> <pre><code>w = window.open('','newwinow','width=800,height=600,menubar=1,status=0,scrollbars=1,resizable=1); d = w.document.open("text/html","replace"); d.writeln('&lt;html&gt;&lt;head&gt;' + '&lt;link rel="stylesheet" type="text/css" href="style.cs"/&gt;&lt;/head&gt;' + +'&lt;body&gt;&lt;/body&gt;&lt;/html&gt;'); // use d to manipulate DOM of new document and display results </code></pre> <p>If I were to do the same thing today (two years of experience later), I'd use some Javascript template library like <a href="http://handlebarsjs.com/" rel="nofollow">Handlebars</a> to maintain a template and compile it to javscript.</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.
    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