?
Solved

Close popup from parent window

Posted on 2003-03-17
11
Medium Priority
?
296 Views
Last Modified: 2013-12-13
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
Comment
Question by:juriaan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
11 Comments
 
LVL 1

Accepted Solution

by:
pcaylor earned 2000 total points
ID: 8151314
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8153074
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
 
LVL 1

Expert Comment

by:Jonza
ID: 8164421
isn't it visibility: hidden??
i'm not sure but...??
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8166509
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8166512
or ...

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

Richard.
0
 
LVL 1

Expert Comment

by:Jonza
ID: 8171918
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8172481
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
 
LVL 1

Expert Comment

by:Jonza
ID: 8172498
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8172522
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question