Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to transport a variable from a popup to window while relying on a function
    primarykey
    data
    text
    <p>Consider the following:</p> <ol> <li><p>Window opens a popup</p></li> <li><p>Popup contains a javascript function which can be triggered by a button</p></li> <li><p>Function takes two predefined arguments and dismisses the popup</p></li> </ol> <p>This is what the JS looks like</p> <pre><code>&lt;script&gt; function dismissPopup(win, myId) { // does some stuff I don't want for THIS routine win.close(); } &lt;/script&gt; </code></pre> <p>This is what the popup's HTML looks like</p> <pre><code>&lt;a id="#bar_1" onclick="opener.dismissPopup(window, '1'); return false;"&gt; now I want this text to be available to window without breaking dismissPopup for other implementations &lt;/a&gt; &lt;a id="#bar_2" onclick="opener.dismissPopup(window, '2'); return false;"&gt; etcetera &lt;/a&gt; </code></pre> <p>What I have tried (window)</p> <pre><code>var win = window.open(url); win.focus(); var original_dismissPopup = window.dismissPopup; window.dismissPopup = function (win, myId) { var FOO = $(win.document.body).find('#bar_' + myId).val(); alert(FOO); original_dismissPopup.apply(this, arguments); }; var X = "I need FOO here" </code></pre> <p>The result is <code>alert(FOO)</code> does give me the correct value. However I don't quite understand how to get the variable outside the function's scope. </p> <p>Also if I comment out the alert the popup is not dismissed at al, it seems my understanding of decorating an existing function is wrong.</p> <p>Thanks for any guidance.</p> <p><strong>UPDATE:</strong></p> <p>This seems to solve things, but I think I'm doing something wrong still:</p> <pre><code>setTimeout(function() { alert(FOO); }, 1500); </code></pre>
    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.
    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