Page 1 of 1
closing a window after a script
Posted: Thu Mar 11, 2004 8:51 am
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?
Re: closing a window after a script
Posted: Thu Mar 11, 2004 9:29 am
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¶m2=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!
Posted: Thu Mar 11, 2004 9:34 am
by yaron
actually he doesn't
all the script does is populating the database.
I'll try your javascript script....
Thanks
Posted: Thu Mar 11, 2004 11:00 am
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?
Posted: Thu Mar 11, 2004 11:05 am
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.)
Posted: Thu Mar 11, 2004 11:11 am
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?
Posted: Thu Mar 11, 2004 11:21 am
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?
Posted: Thu Mar 11, 2004 11:35 am
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?
Posted: Thu Mar 11, 2004 11:37 am
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.
Posted: Thu Mar 11, 2004 11:46 am
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.
Posted: Thu Mar 11, 2004 11:54 am
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.
new seed
Posted: Thu Mar 11, 2004 6:17 pm
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
Posted: Thu Mar 11, 2004 9:38 pm
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){
window.open(url);
}
</script>
Posted: Thu Mar 11, 2004 9:41 pm
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.