It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming HTML Forum

Putting a 'close' button in a frameset

Putting a 'close' button in a frameset

Postby Vid Warren on Sun Dec 07, 2008 2:50 am

Hi, is it possible to put a button in a frameset to close it?

My site, (not currently hosted), has a frameset that stays in the browser window wherever you follow links. The only way of removing the frameset is to type the next address in the address bar or to close the tab/window.

I need to do this without taking the user to a different website. I'd like to put a little 'X' button in the corner so that they could remove the frame easily.

Is this do-able in HTML?

Thanks in advance.


EDIT: I tried

<a href="javascript:' '" onClick="top.close()"> <img src=X.jpg> </a>

That made the frameset blank, but it didn't disappear.
Vid Warren
 
Posts: 16
Joined: Thu Feb 14, 2008 4:27 pm
Location: Bristol

Re: Putting a 'close' button in a frameset

Postby rangana on Sun Dec 07, 2008 4:27 am

You can either remove the element (using the element.parentNode.removeChild(element)), or by toggling it's display property to show/hide at anyone's desire.

Example:
Code: Select all
<a href="#" onclick="
var f1=document.getElementById('frame1');
try{f1.parentNode.removeChild(f1);}
catch(e){alert('First frame already removed.');}
return false;">Remove First Iframe</a> ||

<a href="#" onclick="
var f2=document.getElementById('frame2');
if(f2.style.display=='none'){
f2.style.display='';
this.innerHTML = 'Hide 2nd Iframe';}
else{f2.style.display='none';
this.innerHTML = 'Show 2nd Iframe';}
">Hide 2nd Iframe</a><br><br>

<iframe src="http://www.yahoo.com" id="frame1" style="border:0px;"></iframe>
<iframe src="http://www.google.com" id="frame2" style="border:0px;"></iframe>


Hope that helps.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: Putting a 'close' button in a frameset

Postby Vid Warren on Tue Dec 30, 2008 1:40 pm

Thanks, that worked really well. I've been trying to reply to but it hasn't been working. I didn't realize that this site didn't allow 'html - /html' brackets

EDIT: Now that it is working, I'll show you what I did to modify it .


In my contact section, I have links to htm files that look like this:



Code: Select all

<a href="#" onclick="
var f1=document.getElementById('frame1');
try{f1.parentNode.removeChild(f1);}
catch(e){alert('First frame already removed.');}
return false;">


<style type="text/css">
.noHScroll { overflow-x:hidden; }
</style>

</head>


<span style="position: absolute; top: 1.5%; left: 95%;">

<span onclick="if(document.getElementById('myIMG').style.display=='none') {document.getElementById('myIMG').style.display='none';} else {document.getElementById('myIMG').style.display='none';}" style="color: ccddee; text-decoration: underline; cursor: pointer;">

<img id="myIMG" style="display: block;" src="images/buttons/closebuttonpng.png" width="60%" height="60%" />

</span>

</span>

<body bgcolor=000000>

<iframe src="header.htm" id="frame1" style="border:0px;" width=100% height=4.4% scrolling="no"></iframe>
<iframe  class="noHScroll" src="http://www.myspace.com/vidwarren" id="frame2" style="border:0px;" width=100% height=94%></iframe>

</frameset>



Instead of going to, for example, my Myspace site, users will go to an extension of my site with a frame containing my Myspace and a header frame that will allow them to toggle between other sites.


Thanks again, I'll give you a shout when I get the site hosted so you can see it in action.
Vid Warren
 
Posts: 16
Joined: Thu Feb 14, 2008 4:27 pm
Location: Bristol


Who is online

Users browsing this forum: No registered users and 4 guests