Forcing a window to stay on top?

Discussion in 'Programming' started by axemedia, Feb 8, 2007.

  1. #1
    I have a site that has thumbnail images and when you click the thumbs a pop-up shows the enlarged photo. When you click the next thumb, the pop-up goes under the main window (because we clicked on main window for next thumb).

    The 2nd photo loads in the pop window but that pop window remains under the main window. You have to go hunt for it in your start menu.

    Is there a way to force the pop-up to remain the front window, even after clicking the main window? Perhaps a snippet of Java that will do this.
     
    axemedia, Feb 8, 2007 IP
  2. Munk

    Munk Peon

    Messages:
    56
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Javascript. :) You can't force the popup to stay on top but you can bring it back to the top if the user clicks a 2nd thumbnail. You need to name the popup window when you first open it, then use the window.focus method after opening it.

    Example: http://www.quirksmode.org/js/popup.html
     
    Munk, Feb 10, 2007 IP
  3. axemedia

    axemedia Guest

    Messages:
    1,070
    Likes Received:
    79
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can't seem to get that to work :confused:

    What do you mean by name the window first?

    EDIT:

    This works for IE
    self.focus();

    But not in FF
     
    axemedia, Feb 10, 2007 IP
  4. Munk

    Munk Peon

    Messages:
    56
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I threw together some minimal code that should do what you want.

    Have a look at the window.open method: http://www.devguru.com/technologies/ecmascript/quickref/win_open.html

    and the window.focus method: http://www.devguru.com/technologies/ecmascript/quickref/window.html

    <html>
    <head><title>test</title>
    <script type="text/javascript">
    // you can use the yourimage parameter to decide which image to display
    // I'm not using it and just included it for reference
    function opener(yourimage) {
    
      // open the popup
      newwindow = window.open('http://forums.digitalpoint.com', 'winviewer', 'height=200,width=150');
    
      // make sure popup is on top
      if (window.focus) {newwindow.focus();}
    
      return false;
    }
    </script>
    </head>
    <body>
    <a href="#" onclick="return opener('a')">test a</a>
    <a href="#" onclick="return opener('b')">test b</a>
    </body>
    </html>
    Code (markup):
     
    Munk, Feb 11, 2007 IP
    axemedia likes this.
  5. Munk

    Munk Peon

    Messages:
    56
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I meant instead of doing:
    window.open
    Code (markup):
    to do:
    thename = window.open
    Code (markup):
    so you could then use thename in your focus method.
     
    Munk, Feb 11, 2007 IP
  6. axemedia

    axemedia Guest

    Messages:
    1,070
    Likes Received:
    79
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks Munk

    I'll try those tomorrow.
     
    axemedia, Feb 11, 2007 IP