closing frame window

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

closing frame window

Post by kendall »

Hello,

I have a frame set with two frames

topFrame
mainFrame

i have a link that <a href="javascript:parent.topFrame.close()">close frame</a>

yet onClick it closes the whole window

how do we close the top frame

Kendall
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

hmm.. i never thought you could close a specific frame

or at least i've never seen it done before
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You could try this......

Code: Select all

<a href="javascript:parent.frames.topFrame.close()">close frame</a>
......it's the way I normally target windows in a <frameset>
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

I believe that a document.frame[] array is also created, so you might also try closing frames by:

document.frame[0].close()
document.frame[1].close()
etc
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

microthick wrote:I believe that a document.frame[] array is also created, so you might also try closing frames by:

document.frame[0].close()
document.frame[1].close()
etc
That's basically the same as parent.frames.topFrame where 'topFrame' is the name of the frame you are after, doing it the document.frames[] way means you need to remember which order your frames are in... which is not good if you have a big frameset.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Gen,

Ahh... ok thanks didnt know you had to parent.frames.topFrame.close()

thanks
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Gen,

if the link to close the frame was the top frame itself...would it work?

i dont know man im not getting to work

heres the link http://onlinetnt.com/redirect.php?ID=32
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You cant. Don't hold it against me tho.
As far as I recall, a .frame is a .window, but you cannot close that one (neither in javascript 1.0, 1.1 nor 1.2).

Edit:
Digged this up.
http://devedge.netscape.com/library/man ... ml#1200703
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

JAM,

Hmmmm. this is odd as i wsa reading a tutorial and it said that you could have by referencing the frmes name bu they jus didnt give me an example of the syntax...i guess i have to use and windw.location.href and rest the window to the lower frame url
would this be valid

Code: Select all

<a href="javascript:window.location.href = parent.frames.framename.location.href">close frame</a>
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Ok tried it and got a premission denied...

LOL...Stupid of me to think it was that simple

Kendall
I'm working on it
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I'm not sure if this will work 'cause it's just a thought I had while reading through the topic again.

You could try giving the frame you want to close a style like this......

Code: Select all

<frameset>
<frame src="where_ever" name="frameTop" style="display:block">
</frameset>
......and then for the link href that closes the frame try this......

Code: Select all

<a href="javascript:window.top.frames.frameTop.style.display='none';">close window</a>
Like I said not sure if it's gonna work but it's worth a try.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

ok guys i give up...how do they do that?? isnt it javascript they use
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

you could do instead something like:

<a href="mymainframe.htm" target="_top">Click to remove frame</a>

This won't remove the frame, but just open up the link in the same window so that the frames are gone.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

they being..?

could you show us an example site?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

kendall wrote:ok guys i give up...how do they do that?? isnt it javascript they use

You could get the same effect using an <iframe> in your main page instead of having the site as a <frameset>

You could then do the style="display:none" thing (like I posted above somewhere) but do it with the <iframe>
Post Reply