closing a window after a script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

closing a window after a script

Post by yaron »

Hello all,

I have a tool that kicks off a php script by openning a window with some parameters (get).

What I need to do is to close the browser after the script is finished.
I tried to use javascript using window.close() function but because the window was not opened via javascript it prompts the user before closing.
Is there a way to avoid it?
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: closing a window after a script

Post by TheBentinel.com »

yaron wrote:I have a tool that kicks off a php script by openning a window with some parameters (get). What I need to do is to close the browser after the script is finished.
I don't think you can get around this. It's a leave-the-user-in-control-of-his-machine issue.

Do you really need to open a new window in the first place, though? Could you accomplish the same thing with an image?

Code: Select all

<!-- This is javascript to be run in the browser -->
  <script>
    var image1 = new Image();
    image1.src = "myscript.php?param1=value1&param2=value2";
    // now the browser fires off that URL, it doesn't matter that the
    // the image isn't used anywhere
  </script>
Of course, if your user has to see the contents of the window, then I just wasted your time. If so, sorry!

Hope it helps!
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

actually he doesn't
all the script does is populating the database.
I'll try your javascript script....
Thanks
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

Oh, I just realized:
A window will always be opened as the tool that kicks off the script opens a browser with the right url inside.
How can image help me then?
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

yaron wrote:Oh, I just realized:
A window will always be opened as the tool that kicks off the script opens a browser with the right url inside.
How can image help me then?
Ugh. If the tool is opening the window and you can't control the tool, then the image won't be the answer. Now you're left with displaying a message in the window like "Process complete -- please close this window." At least the user would be asked to do something rather than the user getting the impression you're trying to sneak something past him. (That "The window is attempting to close the browser" message is kinda harsh.)
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

The user requsted for the script to close , as the tool will kick it off about 50 times a day!
As I said all the script does is populating the db which the user can view on a different script.
isn't there a way around it?
is it really impossible?
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

yaron wrote: isn't there a way around it?
is it really impossible?
Absolutes like "impossible" are not for the likes of me to toss around.

Maybe it would be good enough to hide the window, and reuse it each time. If you add a self.blur() into the window somewhere, it should hide itself when it launches. If your tool uses the same window name each time, it would just keeping refreshing the contents of that same hidden window all day. Not a perfect solution, but maybe less cumbersome for your users.

But I don't think you can get around the message. Maybe if I saw what you're seeing I would understand it better. Is there a URL or some code or even a screen shot you can toss my way?
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

I can get you the code but I don't think it will help you.
It's just getting the get data from the url and populate the db (that part works fine) and then need to shut itself down.
There is no screen shot because there is no output to the browser (unless there is an error which in that case I;m not trying to shut the window down).

The blur solution seems to be good enough. if I blur the window and then the tool calls for it again will it really just refresh the same one and not open another one?
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

forgot to mention that this specific window will be used by one user only and that would be the admin of the system.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

yaron wrote:if I blur the window and then the tool calls for it again will it really just refresh the same one and not open another one?
It depends on how it's opened. If the opener specifies the name of the window, then it will reuse the same one over and over. But if it doesn't, then I think the default is to create a new window.

You're kind of at the mercy of whoever wrote the tool on that one.
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

What do you mean by the 'name of the window'?
It will call the same url with different value in the get parameter.
bodge
Forum Newbie
Posts: 7
Joined: Thu Mar 11, 2004 6:13 pm

new seed

Post by bodge »

hey i dont think i really understand what you are trying to achieve but i remember having a problem with my window asking for confirm before closing when using javascript. to get round it i used the php to generate a javascript function which opened up the new window (running php code) then closed it again - as it was called by the first javascript the warning message wasnt displayed
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Just change your link to

Code: Select all

<a href="#" onclick="popup('page.php?p=admin');">Admin Page</a>

Code: Select all

<script language="javascript">
function popup(url)&#123;
window.open(url);
&#125;
</script>
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

yaron wrote:What do you mean by the 'name of the window'?
It will call the same url with different value in the get parameter.
When you open a new window in javascript using window.open, you tell it the "name" of the window in the second parameter. Like this:

window.open("myfile.php?arg1=val1", "MyNewWindow");

The name corresponds to the HTML "target", like when you're using frames. If you open'd a window like this, then created a link with a target="MyNewWindow", then the link would open in that window.

But it sounds like it might all be moot anyway, since bodge's answer sounded so promising. I hope that one works, that gets what you want and avoids the message.
Post Reply