Sand
05-01-2006, 07:42 AM
I can't seem to get self.close() to work on iframes. I know they aren't popups so it's quite normal that they don't but is there a work around?
the problematic code: <input name="submit" type="submit" value="Close" onClick="self.close()"/> works in a popup doesn't in a iframe.
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<SCRIPT LANGUAGE="JavaScript" SRC="dragiframe.js"></SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<script language="javascript" type="text/javascript">
<!--
function popitup(url)
{
newwindow=window.open(url,'name','height=200,width=300,toolbar=no,directories=no,status=no,menubar=n o,scrollbars=no,resizable=no');
if (window.focus) {newwindow.focus()}
return false;
}
// -->
</script>
<script type="text/javascript">
<!--
//Realised by Apachejeff
//www.huntingground.freeserve.co.uk
last_id=""
function frame_pop(id,oLeft,oTop,oPage){
document.getElementById("my_iframe").style.width=parseInt(document.getElementById("cont").style.width)
document.getElementById("my_iframe").style.height=parseInt(document.getElementById("cont").style.height)
if(id!=last_id){
document.getElementById("cont").style.display = "block"
document.getElementById("cont").style.left=oLeft
document.getElementById('cont').style.top=oTop
window.frames["my_iframe"].location=oPage
setTimeout('document.getElementById("headertxt").innerHTML=window["my_iframe"].document.title',200)
last_id=id
}
else{
document.getElementById('cont').style.display = "none"
last_id=""
}
return false
}
// -->
</script>
<div id="cont" style="position:absolute;left:300px;top:200px;width:300px;height:140px;display:none;border:1px solid #000000">
<div id="pop" style="text-align:center;background-color:#FFFFFF"> </div>
<iframe id="my_iframe" name="my_iframe" src="" frameborder="0"></iframe>
</div>
<a href="page1.htm" onclick="return popitup('page1.htm')">Popup</a>
<P><a href="page1.htm" id="lnk1" onclick="return frame_pop(this.id,1000,400,this.href)">I frame (close doesnt work)</a></P>
<body>
</body>
</html>
page1.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div align="center">
<p> </p>
</div>
<p align="center">
<input name="submit" type="submit" value="Close" onClick="self.close()"/>
</p>
</form>
</body>
</html>
the problematic code: <input name="submit" type="submit" value="Close" onClick="self.close()"/> works in a popup doesn't in a iframe.
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<SCRIPT LANGUAGE="JavaScript" SRC="dragiframe.js"></SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<script language="javascript" type="text/javascript">
<!--
function popitup(url)
{
newwindow=window.open(url,'name','height=200,width=300,toolbar=no,directories=no,status=no,menubar=n o,scrollbars=no,resizable=no');
if (window.focus) {newwindow.focus()}
return false;
}
// -->
</script>
<script type="text/javascript">
<!--
//Realised by Apachejeff
//www.huntingground.freeserve.co.uk
last_id=""
function frame_pop(id,oLeft,oTop,oPage){
document.getElementById("my_iframe").style.width=parseInt(document.getElementById("cont").style.width)
document.getElementById("my_iframe").style.height=parseInt(document.getElementById("cont").style.height)
if(id!=last_id){
document.getElementById("cont").style.display = "block"
document.getElementById("cont").style.left=oLeft
document.getElementById('cont').style.top=oTop
window.frames["my_iframe"].location=oPage
setTimeout('document.getElementById("headertxt").innerHTML=window["my_iframe"].document.title',200)
last_id=id
}
else{
document.getElementById('cont').style.display = "none"
last_id=""
}
return false
}
// -->
</script>
<div id="cont" style="position:absolute;left:300px;top:200px;width:300px;height:140px;display:none;border:1px solid #000000">
<div id="pop" style="text-align:center;background-color:#FFFFFF"> </div>
<iframe id="my_iframe" name="my_iframe" src="" frameborder="0"></iframe>
</div>
<a href="page1.htm" onclick="return popitup('page1.htm')">Popup</a>
<P><a href="page1.htm" id="lnk1" onclick="return frame_pop(this.id,1000,400,this.href)">I frame (close doesnt work)</a></P>
<body>
</body>
</html>
page1.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div align="center">
<p> </p>
</div>
<p align="center">
<input name="submit" type="submit" value="Close" onClick="self.close()"/>
</p>
</form>
</body>
</html>