Note that there are some explanatory texts on larger screens.

plurals
  1. POSharing a global javascript object across frames
    primarykey
    data
    text
    <p>This may sound ridiculous but there are some situations when we need to share <code>JavaScript Objects</code> across <code>iframe</code>.</p> <p>When we try to use <code>localStorage</code> for serving the purpose, people say that some browsers might not support it.Even if they support localStorage, Users might've reduced the storage capacity and so forth...<br> So my question is, Do we have a Solution/Alternative to share <code>JavaScript</code> Objects across <code>iframe</code> Below example might get us on the same page</p> <p><strong>parentpage.html</strong></p> <pre><code>&lt;html&gt; ... &lt;head&gt;&lt;script src="script1.js" type="text/Javascript"&gt;&lt;/script&gt;&lt;/head&gt; &lt;body&gt; ... &lt;iframe src="childpage.html"&gt;&lt;/iframe&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>childpage.html</strong></p> <pre><code>&lt;html&gt; ... &lt;head&gt;&lt;script src="script2.js" type="text/Javascript"&gt;&lt;/script&gt;&lt;/head&gt; ... &lt;/html&gt; </code></pre> <p><strong>note</strong>:<br> <em>parentpage.html , childpage.html, script1.js, script2.js</em> reside in the same domain and in the same location</p> <p>Assume that script1.js uses a <code>JavaScript Object</code> that needs to be made publicly available.</p> <p>Since the browser/UserAgent creates a separate <code>Window Object</code> for each additional <code>iframe</code> used in the page and we can't access the <code>Public JavaScript Object</code> if we attach/Extend it to the <code>Window Object/Document Object</code>, The Last hope of it seems to fade away!</p> <p>Is there any Solution/Workaround?</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.
 

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