Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

Close popup from parent window

Hi
I have a php script which checks if a domain is still available. It chechs more then 25 extensions and therefore it take about 10-15 seconds to load.

I want to show a popup with the text -> this will take 10-15 seconds to load please wait. If the php script is ready it has to close the popup.

To open the popup i have used:

<script>
function Openpopup2(newin) {
var venster=window.open(newin,"venster","resizable=no,scrollbars=no,width=250,height=400,top=200,left=200");
          venster.focus();
}
</script>

<form action='template.php?cat=services&content=check' method="post" onclick="javascript:Openpopup2('popupcheck.php')">
<input type='text' name='domein' value='domein'>
<input type='submit' value='start'>
</form>

It opens the popup correctly.
But can anyone give me a hint how to close the popup from php?


0
juriaan
Asked:
juriaan
  • 5
  • 3
1 Solution
 
pcaylorCommented:
Probably the easiest way to do it is to just do something along the lines of:

<?php

//...domain checking code...
// finishes here
echo <<<END
<SCRIPT>
window.close(newin);
</SCRIPT>
END;

The JavaScript will not be executed until your domain checking code is completed.

Alternately, you could put the PHP domain checking code in the HTML file for the popup and change the BODY HTML tag to something like this:
<body onLoad="window.close();">

This will automatically close the window when it finishes loading, which will not occur until your PHP script is completed.  (This is the way I did it in a project of mine)

I hope that helps

-Peter

0
 
Richard QuadlingSenior Software DeverloperCommented:
Exactly.

And a VERY easy 500!

Closing windows (as in opening windows) actually happens only on the client.

PHP code cannot directly open/close windows.

Instead, you would use JavaScript to do this.

JavaScript is NOT Java.

I repeat.

JavaScript is NOT Java.

JavaScript is supported by all the modern browsers (and some not so modern ones too!).

NOTE: Some people do not like popups and run software which will remove them when they load. Under normal circumstances this is not too much of a problem.

Another way to do what you want would be to use DHTML on a single page.

Start off with ...

<div id="waiting">Waiting</div>
<div id="completed" style="visible : hidden">Completed</div>

NOTE: I'm not a CSS expert, but you can "hide" bits.

At the bottom of the page, i.e. where you were thinking of window.close(...);, something like

completed.visible = true;

Not sure on the actual code, but no popups and a very different way!

Richard.
0
 
JonzaCommented:
isn't it visibility: hidden??
i'm not sure but...??
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Richard QuadlingSenior Software DeverloperCommented:
It is something like this. (Just consulting the MS HTML Help documentation ...)

Yep.

visibility:hidden

and

visibility:visible

So...

<div id="waiting" style="visibility:visible;">Waiting</div>
<div id="completed" style="visibility:hidden;">Completed</div>


at the top and at the bottom ...

<script language="JavaScript"><!--
waiting.style.cssText = 'visibility:hidden;';
completed.style.cssText = 'visibility:visible;';
//--></script>

should do the trick.

Richard.
0
 
Richard QuadlingSenior Software DeverloperCommented:
or ...

<script language="JavaScript"><!--
waiting.style.visibility = 'hidden';
completed.style.visibility = 'visible';
//--></script>

Richard.
0
 
JonzaCommented:
but that trick doesn't work with older browsers...

so you need to close a popup when all the PHP code have been executed?

Couldn't you use PHP for determining when the code is ready.. Put the code:
print("<script type='text/javascript'>window.close(newin);</script");

after your domain check loop and then the PHP should print the window.close after all the domain check is done?
0
 
Richard QuadlingSenior Software DeverloperCommented:
Older sites are an issue, but so what. I have done 15 sites.

Over 95% of the hits on all the sites are IE5+

Over 98% of the hits on all the sites are IE.

Netscape/Opera/WebTV are now so minimal, that support for them is a headache.

Just because Betamax video players exists doesn't mean we can still buy tapes for them.

The browser war has been won by Microsoft. Move on.

Richard.
0
 
JonzaCommented:
RQuading..
The most reliable way still is to use PHP.
why use some other technique when you can close the window automatically after PHP has been executed.

and you are saying that almost everyone uses IE..
Well the procents are true but did you know that many corporations does only have netscape 4.x browsers. Thats pretty stupid actually but you still want the corporations and their workers to browse your site, right?
0
 
Richard QuadlingSenior Software DeverloperCommented:
I don't stop them from browsing the site.

The JavaScript method is fine and will work on a lot of browser versions.

My CSS method was an alternative. In my opinion, it is "better" as far as a popup is bloody irritating and if you run anti-popup software, there may be consequences to the site's code (errors on page sort of thing).

CSS is supported by a LOT of browsers so the number of users NOT getting this is probably very small.

Another way is to use both, but only the popup if the browser is old and doesn't support the CSS method.

Richard.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now