self.close and parent.location in one link

M

michal.podlewski

Hi All,
I have a problem with a simple (as I thought till now) thing:
I want to make a link in a child-window which would change site in the
parent-window and along with closing child window. The parent window
name is "main". A made a link like this in the child-site:

<a href="new_address.html" target="main" class="about"
onclick="javascript:main.location='new_address.html';self.close();">
change and close </a>

but it does not work.
I tried also window.close(), window.close(self) and alo put it all in
href instaed of onclick - without success. Although the page in "main"
changes to what I want, but the pop-up is still open.
Strange is that self.close() invoked without anything before it work
normally.

Do you have any idea how can I solve this problem?

Thanks in advance and best regards,
Michal
 
S

SAM

(e-mail address removed) a écrit :
Hi All,
I have a problem with a simple (as I thought till now) thing:
I want to make a link in a child-window which would change site in the
parent-window and along with closing child window. The parent window
name is "main".

What about are you talking when you say "parent" window ?
Are you in a framed page ?
(and you really talk of parent's frame or container of the frame)
A made a link like this in the child-site:

and ... what could be a "child-site" ?
<a href="new_address.html" target="main" class="about"
onclick="javascript:main.location='new_address.html';self.close();">
change and close </a>

but it does not work.

What is not working ?
You can't close a frame (or iframe), the more you can do is to hide it,
or to suppress it from main page's DOM tree.

If you're talking of framed page (frameset) it is something like :
onclick="parent.main.location = ...
or simply :
onclick="parent.location = ...
and you cant "close" the iframe or frame from its loaded file.
(in any case by 'self.close()' )
I tried also window.close(), window.close(self)

So youren't in a framed page and you're talking about *mother* and
*daughters* windows (popups), no ?

The 'mother' is the "opener" of the 'daughter' and not hers "parent"
In JS a 'parent' is always a 'container' and never an ancestor (previous
and independent object).

<a href="new_address.htm"
onclick="opener.location=this.href; self.close()">Modify</a>

The html target cant reach the 'opener', a target must be an html name
of something displayed in the same window (ie: another frame).
 
T

Thomas 'PointedEars' Lahn

I want to make a link in a child-window which would change site in the
parent-window and along with closing child window. The parent window
name is "main". A made a link like this in the child-site:

<a href="new_address.html" target="main" class="about"
onclick="javascript:main.location='new_address.html';self.close();">
change and close </a>

but it does not work.

It is not supposed to. Provided `main' is a reference to the same object as
`window.opener' -- which is far from certain --, and `self' as `window',
then you are trying to close the window that you are trying to navigate to
as you do not suppress the default action for the `click' event of the
a[href] element.

I tried also window.close(), window.close(self) and alo put it all in
href instaed of onclick - without success.

IOW, fantasy coding. You expected that to work, somehow by coincidence?
Although the page in "main" changes to what I want, but the pop-up is still open.
Strange is that self.close() invoked without anything before it work
normally.

You cannot close windows with scripting that have not been opened with
scripting, a well-known security measure for keeping maliciously or
incompetently developed Websites to mess with your working environment.
It might apply here.
Do you have any idea how can I solve this problem?

Read, think, code. In that order.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top