www.webdeveloper.com
Results 1 to 3 of 3

Thread: IFRAME + javascript close()?

  1. #1
    Join Date
    May 2005
    Posts
    46

    IFRAME + javascript close()?

    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.

    Code:
    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=no,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

    Code:
    <!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>&nbsp;</p>
      </div>
      <p align="center">
        <input name="submit" type="submit" value="Close" onClick="self.close()"/>
      </p>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    May 2005
    Posts
    46
    i have tried:

    Code:
    <script>
    function closeiframe(){
    parent.document.getElementById("masterdiv").style.display="none"
    }
    </script>
    Code:
    <a href="javascript:closeiframe()">Close iframe</a>
    and nothing happens :/

  3. #3
    Join Date
    May 2005
    Posts
    46
    got this solved by changing masterdiv (the iframe reference) to cont. But i still have one problem, i close the window but if i try opening it again it ages to clicks...any ideas? andi would appreciate if there are any ideas to solve my other prob:
    http://www.webdeveloper.com/forum/sh...d.php?t=105052
    Last edited by Sand; 05-01-2006 at 09:23 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles