Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are three solutions I propose depending on what the problem actually is.</p> <h2>1) closepopup() does not work on other pages</h2> <p>If you need to close the popup from page B when it was opened from page A the following code will allow you to obtain a reference to the popup from page B and close it. <strong>Reference: <a href="https://stackoverflow.com/questions/2455158/find-window-previously-opened-by-window-open">Find window previously opened by window.open</a></strong></p> <p><strong><em>PageA.html</em></strong> </p> <pre><code>&lt;script&gt; function popuponclick() { my_window = window.open("http://google.com", "mywindow","status=1,width=350,height=150"); } function closepopup() { my_window.close (); } &lt;/script&gt; &lt;a href="javascript:popuponclick()"&gt;Open window...&lt;/a&gt;&lt;/br&gt; &lt;a href="PageB.html"&gt;Go to Page B&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong><em>PageB.html</em></strong></p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script&gt; function closepopup() { var popupPlayer= window.open('', 'mywindow', 'status=1,width=350,height=150') ; popupPlayer.focus(); popupPlayer.close(); } &lt;/script&gt; &lt;a href="javascript:closepopup()"&gt;Close window...&lt;/a&gt;&lt;/br&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h2>2) closepopup() does not work on the same page as window is opened</h2> <p>A global reference to my_window is needed so you would need to change the code like this:</p> <pre><code> var my_window; //global reference here function popuponclick() { my_window = window.open("", "mywindow","status=1,width=350,height=150"); } function closepopup() { my_window.close (); } </code></pre> <h2>3) Final third solution using frames</h2> <p>You separate your page into 1 frames (one which is 100%) and another that is 0%.</p> <p>You add the window open/close code in the parent frame. Than you call the window control code via cross frame javascript commands.</p> <p><strong><em>Frames HTML Containing Javascript</em></strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;My example&lt;/title&gt; &lt;script&gt; var my_window; function popuponclick() { my_window = window.open("", "mywindow","status=1,width=350,height=150"); } function closepopup() { my_window.close (); } &lt;/script&gt; &lt;/head&gt; &lt;frameset cols="100%,0%"&gt; &lt;frame src="frame.html"/&gt; &lt;frame/&gt; &lt;/frameset&gt; &lt;/html&gt; </code></pre> <p><strong><em>Internal Frame (frame.html) - calling parent Javascript</em></strong></p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;a href="javascript:parent.popuponclick()"&gt; Open Window &lt;/a&gt;&lt;br/&gt; &lt;a href="javascript:parent.closepopup()"&gt; Close Window &lt;/a&gt;&lt;br/&gt; &lt;a href="javascript:location.href=location.href"&gt; Refresh Frame (and try again)&lt;/a&gt;&lt;br/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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.
 

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