# Closing safari windows



## brutfood (Apr 22, 2004)

It's the small hours of the morning, and I'm confused, tired and losing hope.  All evening/night I've been trying to accomplish a simple objective.  To close a safari browser window.

The situation is a little complicated.  I have a php script, containing a .swf (flash movie).  The flash does it's job (a bit of communication with some flash in another window), and the does a getURL('javascript: window.close());

- I've tested it in explorer, works fine - window closes.

So I started playing around with stuff.  Made a javascript function called closeme().

function closeme() {window.close();};

Tried calling that instead.  Still hasn't worked.

I've stared and stared at my syntax, in case Safari is picky - looks ok to me.  This isn't the first weird thing to happen.  I noticed before that <BODY onload="window.moveTo(0,0);... had no effect.

Is it me - or is there an issue, or even a workaround I should know about?

Mac OS v 10.3.2, Safari 1.2 (v125)


----------



## brutfood (Apr 22, 2004)

Ignore the underscores above in the word javascript.  I don't think I typed them - I'm not sure why they were inserted?


----------



## Lycander (Apr 22, 2004)

brutfood said:
			
		

> Ignore the underscores above in the word javascript.  I don't think I typed them - I'm not sure why they were inserted?


Maybe that's the syntax in Flash?

As for your problem, just for ha-ha's, did you by chance disable scripting in Safari preferences? I've been doing some Google searching and haven't found much yet, but what you ought to be looking for is resources around KHTML and Javascript, since Safari uses KHTML to render web pages.


----------



## Lycander (Apr 22, 2004)

Try <BODY onLoad="javascript:closeme();" ... >

or just

<BODY onLoad="javascript:window.close();" ... >


----------



## Lycander (Apr 22, 2004)

Forget my last post, it doesn't work I tried it.

Did some reading and apparently "window.close()" is not allowed on the main window. In Internet Explorer it works because MS is stupid, but other HTML implementations won't allow it because of security reasons or whatever. But I think if you were to spawn a new window you'd be able to close the child window.


----------



## twister (Apr 22, 2004)

I even tested it and it work on a mac in Safari and IE  

On you button put 
on(press){
getURL("javascript:self.close()");
}


----------



## brutfood (Apr 22, 2004)

Ok, I'm not allowed to close the main window.  Well, I wasn't really.  Well, I was opening a new window from within flash.  But it all depended how I open that window:

If I open the window using: getURL(url,windowname); - then the self.close() had no effect.

If I open the window using: getURL('javascript: window.open("'+url+'")'); - then the self.close() works.

One more thing though...

Can I open and close a child window from a parent window?  Well, I know I can open it, but can I close it from the parent?  I've tried, and either I can't - or I'm messing the syntax up?

(again, ignore the underscores - they're inserted by this forum, not me)


----------



## anarchie (Apr 22, 2004)

```
mywindow = window.open(url)
mywindow.close();
```


----------



## Arden (Apr 26, 2004)

Lycander said:
			
		

> In Internet Explorer it works because MS is stupid...


Sorry, but at 4:40 in the morning I find this extremely funny.  ::ha::

I'd imagine you could close a window if you passed your function a parameter to close window X, where the window you opened was named X.  I'm not too hot on Javascript so I'm not sure how to do this exactly, but hopefully you get the idea.


----------

