Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript function call across HTML windows
    primarykey
    data
    text
    <p>According to <a href="https://stackoverflow.com/questions/87359/can-i-pass-a-javascript-variable-to-another-browser-window">this</a> page I should be able to call parameters and functions of child windows, but it is not working for me.</p> <pre><code>var w = window.open("index.html"); console.log(w); console.log(w.foo); </code></pre> <p><code>console.log(w)</code> shows that there is a function named <code>foo</code> but <code>console.log(w.foo)</code> outputs <code>undefined</code>. Is this a security issue?</p> <hr> <p><strong>EDIT</strong> Here is some more functionality:</p> <p>child.html (omitting the body):</p> <pre><code>&lt;head&gt; &lt;script type="text/javascript"&gt; test = 123 ; function foo(arg){ //do something } &lt;/script&gt; &lt;/head&gt; </code></pre> <p>parent.html: </p> <pre><code>var w = window.open("child.html"); console.log(w); //outputs all the methods and parameters console.log(w.foo); //outputs 'undefined' console.log(w.test); //outputs 'undefined' </code></pre> <hr> <p><strong>EDIT 2</strong> Also I should explain why I need to pass arguments as someone will inevitably ask me why I can't 'just hard code it'. I have an HTML canvas element, and every time the user right clicks, there is a right click menu with the option 'list shapes underneath'.</p> <p>When the user clicks this menu item, I want to pass a list of all the shapes underneath that click and to display it in a new window. Here are the problems I am facing:</p> <ol> <li><p>I can't pass it as an argument b/c I don't know whether the window has been loaded (I can't seem to change the <code>onload</code> function either)</p></li> <li><p>I can't have the child window query the parent window b/c the right click menu disappears after clicking it.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    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