SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,094
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    popup window onFocus() . . . Need a push.

    Hi all,
    I have a popup timer and would like to option of keeping the popup on top of the parent window.
    Here is what I have so far.
    Code:
    Two radio buttons
    <input name="ontop" class="ontop" type="radio" value="y" Onclick="ontop('y')">y 
    <input name="ontop" class="ontop" type="radio" value="n" Onclick="ontop('n')">n 
    
    The JS
    
    function ontop(yn) {
      document.getElementById("ontop")
      if (yn == 'y'){
      alert ("Focus");
      self.focus(); 
      }
      else{}
    }
    I get the alert but the popup doesn't stay on top.
    Can anyone help with a solution? This (I hope) has a simple solution.
    Thanks.
    What I lack in acuracy I make up for in misteaks

  2. #2
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    Do you mean it doesn't continue covering the original window if you move the focus (or just click) on the original window?

  3. #3
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,094
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Exactly, window pops up but any click on the parent and the popup goes behind.

    I even called the function from body onload, got the alert but still went behind the parent.
    What I lack in acuracy I make up for in misteaks

  4. #4
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    Thing is, I thought which window is on top was controlled by the users Windowing manager (so Windows, or Gnome, or KDE, or whatever Mac people use), not Javascript. Someone can enlighten me if I'm wrong, but I'm thinking this is outside the power of Javascript.

  5. #5
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,094
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm coming to the conclusion that with tabbed browsers (which tab is parent) that this feature is no longer supported. Here is a link and I'm sure it worked at some point and I don't see a date.

    http://javascript.internet.com/page-...op-window.html

    As you can see it doesn't work. I will quit banging my head and move on. I will keep looking here to see if an answer arises though. It would be a nice feature to have.

    Thanks.
    What I lack in acuracy I make up for in misteaks

  6. #6
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you combine some CSS and Javascript?
    Something like this

    Code:
    <html>
    <head><title>onTop</title>
    <style type="text/css">
    #ontopDiv{
       display:none;
       z-index:2;
       background: #orange;
       color:#000;
       width: 200px;
       height: 200px;
       padding:10px;
       left:200px;
       position: absolute;
    }
    </style>
    
    <script type="text/javascript">
    function onTop(value)
    {
    	if(value =='y'){
    	document.getElementById("ontopDiv").style.display = 'block';
    	}else if(value =='n'){
    	document.getElementById("ontopDiv").style.display = 'none';
    	}
    }
    </script>
    </head>
    <body>
    
    <div id="ontopDiv">Yes I am on top!</div>
    <label>Show div</label><input name="ontop" class="ontop" type="radio" value="y"  onClick="onTop('y')" /> 
    <label>Hide div</label><input name="ontop" class="ontop" type="radio" value="n"  onClick="onTop('n')" />
    </body>
    </html>
    You can easily at a timer to the Javascript function so that div opens / closes after the indicated time. Hopefully this helps a bit.


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
  •