How to name the 1st window ?

P

Piotr

Hi,

I have a big main window, prepared in html, and a small one, opened by
window.open in <script> in main window script.
I would like to click in small one and open sth in main one. How to do it?

There is "target", but how to traget the 1st window?

Thanks,
Peter
 
I

Ivo

Piotr said:
Hi,

I have a big main window, prepared in html, and a small one, opened by
window.open in <script> in main window script.
I would like to click in small one and open sth in main one. How to do it?

There is "target", but how to traget the 1st window?

Thanks,
Peter

This line of script will attch a name to the current window:
top.name="mainwin";
You can add this to the script in the main window and any links in the popup
with target="mainwin" will open in the main window. This way you don't need
script in the popup. You can also refer to the main window from the popup
with "opener". This line of script in the popup:
opener.location.href="nextpage.html";
will open a new page in the opener, regardless of whether or not has a name.
HTH
Ivo
 
D

DU

Piotr said:
Hi,

I have a big main window,

Big main window is often referred as opener. Also parent window.

prepared in html, and a small one,

Often referred as secondary window, or child window or sub-window (best
technical term, IMO) or popup window.

opened by
window.open in <script> in main window script.

Make sure you hold, keep a window object reference to that sub-window.
This is highly useful in scripts creating sub-windows; you may want to
re-use, recycle that sub-window or just be able to bring it back in
front of the opener. The general idea is, e.g.

<script type="text/javascript">
var WindowObjectReference;
function OpenRequestedPopup(strUrl, strTarget)
{
if(WindowObjectReference == null || WindowObjectReference.closed)
/*
if the sub-window does not exist or if it was closed, then create it
*/
{
WindowObjectReference = window.open(strUrl, strTarget,
"resizable,status,scrollbars,top=100,left=250,width=400,height=300"
}
else
/*
else just bring the sub-window back in front of the opener
*/
{
WindowObjectReference.focus();
};
}
</script>

And in the html:

<p><a href="path/MyGarden.html" target="ANewSubWindow"
onclick="OpenRequestedPopup(this.href, this.target); return false;"
title="Clicking this link will create a new separate window">See my
garden said:
I would like to click in small one and open sth in main one. How to do it?

Giving an url showing what you have done so far and what are your files
is always more convenient.
There is "target", but how to traget the 1st window?

target is primarly used to target a frame or a sub-window from the opener.
Thanks,
Peter

In the sub-window, add this:
<p><button type="button" onclick="if(opener)
{opener.location.href='path/filename.html';};">Load filename in
opener</button></p>


http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/opener.asp

http://www.mozilla.org/docs/dom/domref/dom_window_ref77.html#1019352

http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/open_0.asp

http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/window.html#1202731

DU
 
P

Piotr

Finally I used <A HREF="javascript:window.opener.location.href=blabla>

Thank you very much!

Peter
 
T

Thomas 'PointedEars' Lahn

Piotr said:
Finally I used <A HREF="javascript:window.opener.location.href=blabla>

That's nonsense, see the FAQ and <http://validator.w3.org/>.
Use

<script type="text/javascript">
function setOpenerLoc(sURI)
{
if (window.opener
&& !window.opener.closed
&& typeof window.opener.location != "undefined")
{
window.opener.location = sURI;
}
return false;
}
</script>

<a href="#"
onclick="return setOpenerLoc('blabla');"

instead. It would be better if you also wrote that link dynamically so
that users without script support do not encounter "malfunctioning" links:

<script type="text/javascript">
// ...

document.write(
'<a href="javascript:void(setOpenerLoc(\'blabla\'))"'
+ ' onclick="return setOpenerLoc(\'blabla\');">'
+ '...'
+ '<\/a>');
</script>


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,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top