Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close control panel window 1

Status
Not open for further replies.

jockm

Technical User
Aug 13, 2002
41
0
0
GB
I have a line of code on my navbar that opens a control panel in a small newWindow.

<a href=&quot;javascript: newWindow('booking.html')&quot;>Control Panel</a>

In the control panel window I have a few links, a sample one of which is

<A HREF=&quot; TARGET=&quot;main&quot;>Make a new booking</A>.

Fine, the link works, it opens the new URL in the main frame, but the control panel window doesnt close. It remains open in the background behind the main window. Normally, that wouldnt matter, but if later another control panel is called, it goes into that hidden window behind the main window, and to the viewer it appears that nothing has happened.

How do I close my control panel when one of its links is activated?
 
Jemminger hi

Strangely enough your code failed. It closes the control panel window, yes. But instead of opening up the new href in the target=main, it re-opens the control panel in the main frame.

Maybe I didnt understand what you meant by href=&quot;#&quot;. Is # a placeholder that I need to replace with something concrete?

thanks for help here anybody
 
oops...try this:
[tt]
HREF=&quot;#&quot; onclick=&quot;opener.location.href = ' TARGET=&quot;main&quot;>Make a new booking</A>
[/tt]

the &quot;#&quot; makes the link act as if it is a link to an anchor on the page, like &quot;page1.html#top&quot;. it's just a shortcut to making the browser treat the tag as a hyperlink when you actually want script to handle its operation.
=========================================================
if (!succeed) try();
-jeff
 
Thanks Jeff. Now what happens is this:

1) the control panel window closes.

2) it opens up in Target=&quot;main&quot; (one of the three frames in my frameset)

2) Then the href opens in another of my frames, the navbar frame (which was in fact the opener of the control panel).

I tried moving the Target='main' around in to different places in the script, but got no joy so far. What do you recommend I try next?

--jock--
 
i see... i think this should do it, provided the frame you want the control panel to affect is named &quot;main&quot; - is this what you're after?
[tt]
<A HREF=&quot;#&quot; onclick=&quot;opener.parent.main.location.href = ' a new booking</A>
[/tt] =========================================================
if (!succeed) try();
-jeff
 
Thanks Jeff, I'll go and try it and let you know. But first I have a basic question: if I close the window of a document, and I write some more code after that window.close() statement, will that code ever get executed?

Or, the moment the window closes, that finishes that document's ability to do anything? I suppose this seems like a naive question, but I can't find the answer to it in any of the books I have on javascript. If I can continue to execute code after the window is closed, then I figure I can easily enough open up another document where I want it to open. Or at least have a try at it!
 
Jeff, fine. We're in business.

<A HREF=&quot;#&quot; onclick=&quot;opener.parent.main.location.href = ' a new booking</A>

Works perfectly as I was wanting. I still feel quite frustrated, tho, because I can't seem to really master the PRINCIPLES of Javascript. I can copy what others tell me, but I can't seem to understand the basics well enough to create what I want myself. How could I figure out that the parent of the opener is necessary? Is the parent the index.htm file that defines the frameset, and without that the Target=&quot;main&quot; simply wasnt recognised? I have javascript for Dummies, I have O'Reilly Javascript the definitive guide, but none of them seem to really help me get the basics so I can myself write anything.

Luckily this forum exists, or I would have given up ages ago. But it must be boring for you chaps to have to keep giving the same help over and over. Or dont you see it that way?
 
hi jock,

after you call window.close(), no script after will execute.

the o'reilly javascript definitive guide is a very good book - i've read it from cover to cover about twice now.

the reason we ended up with the code we did is this:
- &quot;opener&quot; got us to the window that created your control panel,
- then &quot;parent&quot; got us to the main window object since your page contains frames,
- then we use &quot;main&quot; to access the frame you've named &quot;main&quot;.
this last step could also have been accomplished using the frame's index in the parent's zero-based array of frames: if your target frame is the second frame defined in your frameset, the code could alternately have been written:
[tt]
opener.parent.frames[1].location.href = &quot;[/tt]

no difference in action...using names is a bit easier to read, but using indexes can be useful if you don't know the frame's name but you do know it is the second frame.

sometimes the simplest solutions elude me: i did some testing just now, and it looks like we could have done the same thing with this:
[tt]
<A HREF=&quot; TARGET=&quot;main&quot; onclick=&quot;window.close();&quot;>Make a new booking</A>.
[/tt]

=========================================================
if (!succeed) try();
-jeff
 
Jeff,
Thanks for your help with figuring this out. I havent tried your last version, as I will stay, for the moment, what is now working.

I also very much appreciated your explanation of how to access the frames. I have a non-frames version of the side as well, as I was able to get the code to work there simply by eliminating OPENER.PARENT, because I was able to understand better what I was doing.

Probably a lot of people who are writing js have had experience with C++ and or Visual Basic and are familiar with object-oriented programming. I'm not, and although I study the books I have and would be ready to buy more, I really dont yet have a feel for how to do creative things with js. I can just copy a script and use it, but if I need something different, I come here and get help.

jock
 
jock,
pretty much sounds like how i started...once i got a little more familiar with js, i started making or attempting to make every little idea i had (no matter how trivial)...this led to a deeper understanding of how it works...plus i've had some help from tek-tips too :)
...now i have about 200 little exercises i've written that taught me one thing or another...one of these days i'll get around to posting them on my site ( for fun

programming is fun! keep learning - amazon.com & half.com are great resources for used books.
=========================================================
if (!succeed) try();
-jeff
 
Jeff

Thanks for the encouragement. I'm glad to hear you had to do it by trial and error as well. And yes, please DO post the exercises where you learned something from each one. I will go there the instant you do it to start working through them. And I reckon I won't be alone! You'll get quite a few stars here for that.

In a way, that could be the missing ingredient from all the existing textbooks--perhaps you could be on your way to a new book that fills the vacuum.

jock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top