SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.onunload= function() { hideDiv(); } //there is a problem in Opera

    My code works in Firefox.
    There is a problem in Opera 9.23
    After I click X to close the popup, main.htm is grey. main.htm must be white. Div must be hidden. What can I do? Thanks...
    main.htm
    Code:
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
      <meta content="text/html; charset=UTF-8"
     http-equiv="content-type">
      <title></title>
    <style type="text/css">
    .transparent {
    position:absolute;
    left:0px;
    top:0px;
    width:100&#37;;
    height:100%;
    display:none;
    z-index:-1;
    background-color: #EAEAEA;
    -moz-opacity:0.95;
    filter:Alpha(Opacity=95);
    opacity: 0.95;
    -khtml-opacity: 0.95;
    }
    </style>
    <script type="text/javascript">
    function openPopup() {
    var pencere = window.open("popup_window.htm","title of window", "height=450,width=400");
    var el = document.getElementById('divid');
    el.style.display= "block";
    el.style.zIndex = "1";
    }
    </script>
    
    </head>
    <body id="bodyid">
    <input type="button" value="open popup" onclick="openPopup()">
    <br>
    <div id="divid" class="transparent">
    </div>
    </body>
    </html>
    popup_window.htm
    Code:
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <title></title>
    <style type="text/css">
    </style>
    <script type="text/javascript">
    function hideDiv() {
    var el = opener.document.getElementById('divid');
    el.style.zIndex = "-1";
    el.style.display="none"; 
    }
    window.onunload= function() { hideDiv(); }
    
    </script>
    </head>
    <body>
    <input type="button" onclick="hideDiv(); window.close()" value="close me and return main page">
    ayşe buradaydı
    </body>
    </html>
    Bismillahirrahmanirrahîm
    Bizi doğru yola, kendilerine nimet verdiklerinin yoluna ilet; gazaba uğrayanların ve sapıklarınkine değil.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    with Opera

    Try it without the spaces in "title of window"

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mittineague,
    I tried your suggestion but result is same.
    I wrote the following code in Opera. Message box did not seem. I think Opera don't know window.onunload.
    Code:
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <title></title>
    <style type="text/css"></style>
    <script type="text/javascript">
    
    window.onunload = function() { alert('your message'); }
    
    </script>
    </head>
    <body>
    </body>
    </html>
    Last edited by muazzez; Nov 28, 2007 at 02:57.
    Bismillahirrahmanirrahîm
    Bizi doğru yola, kendilerine nimet verdiklerinin yoluna ilet; gazaba uğrayanların ve sapıklarınkine değil.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    onunload in Opera

    Opera does indeed support onuload. This works
    opener.htm
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
      <meta content="text/html; charset=UTF-8"
     http-equiv="content-type">
      <title>opener</title>
    <style type="text/css">
    .transparent {
    position:absolute;
    /* changed pos + dim */
    left:100px;
    top:100px;
    width:25&#37;;
    height:25%;
    display:none;
    z-index:-1;
    background-color: #EAEAEA;
    /*
    -moz-opacity:0.95;
    filter:Alpha(Opacity=95);
    opacity: 0.95;
    -khtml-opacity: 0.95;
    */
    }
    </style>
    <script type="text/javascript">
    function openPopup() {
    /* removed spaces, changed dim, added pos */
    var pencere = window.open("popup_window.htm","title_of_window", "height=100,width=200,left=200,top=100");
    var el = document.getElementById('divid');
    el.style.display= "block";
    el.style.zIndex = "1";
    }
    </script>
    
    </head>
    <body id="bodyid">
    <!-- added semi-colon -->
    <input type="button" value="open popup" onclick="openPopup();">
    <br>
    <div id="divid" class="transparent">
       divid
    </div>
    </body>
    </html>
    popup_window.htm
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <title>popup_window</title>
    <style type="text/css">
    </style>
    <script type="text/javascript">
    function hideDiv() {
    var el = window.opener.document.getElementById('divid');
    el.style.zIndex = "-1";
    el.style.display="none"; 
    }
    window.onunload = hideDiv;
    
    </script>
    </head>
    <body>
    <input type="button" onclick="window.close();" value="close me and return main page">
    ayse buradaydi
    </body>
    </html>
    When you click on the button, the script inside the page closes the window, firing the onunload event.


Bookmarks

Posting Permissions

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