We help IT Professionals succeed at work.

pop up windows via JavaScript

303 Views
Last Modified: 2012-06-27
I have a net4 application that opens a pop up window via JavaScript

The pop up window is long and narrow and works well with the main window.

There is a button on the main window where the user can click a to get additional information.

That information is in the pop up.

The FIRST time the user clicks the button, the pop up appears on top of the main window.
(I do not close the pop up.)

The next time the user clicks the more info button, the pop up window does not appear on top of the main window.  It is behind the main window.

I want to pop up to always appear on top of the main window.

I have tried to set the focus to the pop up in JavaScript, but it does not seem to work.

I do not know JavaScript, and I am not a professional developer.  

Here is the java that I use.

    function poponload() {
       
       
        testwindow = window.open("<%= TextBox_i_re.text %>", "mywindow", "left=10,location=0,toolbar=0,menubar=0,status=0,resizable=0,scrollbars=yes,toolbar=0,width=600,height=3100");
        testwindow.moveTo(0, 0);
        openPreviewWindow('', 1);
        testwindow.focus();

           }
</script>

Thanks for the advice.

WCGee
Comment
Watch Question

IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the suggestions.

I pasted it into my aspx page.  It opened the pop up window ok, But once the pop up was opened, the contents of the popup changed ok, but the pop up did not move in front of the main window.

Also, the openpreviewwindow line if found while looking around.  I have no idea what it does.

Thanks again, any other insights?

WCGee
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Please remove that then!!! It gives an error that stops the line with the focus from executing...
A little knowledge is a dangerous thing ;))))

Author

Commented:
I did remove it. Pop-up still behind main after first pop.
Here is code.

<script type="text/javascript">
    var testwindow;
    function poponload() {
        if (testwindow && !testwindow.closed) testwindow.close();
        testwindow = window.open("<%= TextBox_i_re.text %>", "mywindow", "left=10,location=0,toolbar=0,menubar=0,status=0,resizable=0,scrollbars=yes,toolbar=0,width=600,height=3100");
        testwindow.moveTo(0, 0);
       
        testwindow.focus();

    }
</script>

Thanks for your help.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Try this

<script type="text/javascript">
    var testwindow;
    function poponload() {
        if (testwindow && !testwindow.closed) testwindow.close();
        testwindow = window.open("<%= TextBox_i_re.text %>", "mywindow", "left=10,location=0,toolbar=0,menubar=0,status=0,resizable=0,scrollbars=yes,toolbar=0,width=600,height=3100");
        testwindow.moveTo(0, 0);
        setTimeout(function() { testwindow.focus();},100);

    }
</script>

Open in new window

Author

Commented:
PU still stays behind main.

thanks
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
New approach:
http://jqueryui.com/demos/dialog/#modal
Much more reliable
Here is how to load the dialog with the URL from the same server
http://forum.jquery.com/topic/loading-existing-html-pages-into-a-jquery-dialog-window

Author

Commented:
mplungjan,

thanks, I took a look and it is impressive.  However it is a bit more complicated than I am prepared to dive into. I need simple.

thanks for your input.

Author

Commented:
mplungjan,

Here is java script I put in my aspx page.


========================================================================
<script type="text/javascript">
    function popuponclick()
        {
       
     my_window = window.open("<%= TextBox_i_re.text %>", "mywindow", "left=660,location=0,toolbar=0,menubar=0,status=0,resizable=0,scrollbars=yes,toolbar=0,width=580,height=3100");
     if (window.focus) { my_window.focus() }
     
 }
     function closepopup()
    {
        if (false == my_window.closed) {
            my_window.close();
        }
        else {
            alert('Window already closed!');
        }
    }
</script>
========================================================================


Here is the html that is in the body of the aspx page that the user clicks to open the pop up window.

========================================================================
 <span class="style110">&nbsp;&nbsp;<span class="style111"><span
            class="style112"><strong> </strong></span>
        <a href="javascript: popuponclick()" style="z-index: 1"><span class="style112">
        <strong>Photos/Map</strong></span></a></span></span>


=========================================================================

The script is very close to what you had provided.  I did some more research using what you provided. Not sure why it did not work for me as you provided.  

This works great, exactly what I wanted, it also works on IPAD.

To your point, a little knowledge is a dangerous  thing, … but even a blind hog can find an acorn if he roots long enough, particularly if someone shows him the right tree.  You showed me the tree.  You get the 500 points, and I get the acorn ;-)

WCGee

Author

Commented:
mplungjan,

Here is java script I put in my aspx page.


========================================================================
<script type="text/javascript">
    function popuponclick()
        {
       
     my_window = window.open("<%= TextBox_i_re.text %>", "mywindow", "left=660,location=0,toolbar=0,menubar=0,status=0,resizable=0,scrollbars=yes,toolbar=0,width=580,height=3100");
     if (window.focus) { my_window.focus() }
     
 }
     function closepopup()
    {
        if (false == my_window.closed) {
            my_window.close();
        }
        else {
            alert('Window already closed!');
        }
    }
</script>
========================================================================


Here is the html that is in the body of the aspx page that the user clicks to open the pop up window.

========================================================================
 <span class="style110">&nbsp;&nbsp;<span class="style111"><span
            class="style112"><strong> </strong></span>
        <a href="javascript: popuponclick()" style="z-index: 1"><span class="style112">
        <strong>Photos/Map</strong></span></a></span></span>


=========================================================================

The script is very close to what you had provided.  I did some more research using what you provided. Not sure why it did not work for me as you provided.  

This works great, exactly what I wanted, it also works on IPAD.

To your point, a little knowledge is a dangerous  thing, … but even a blind hog can find an acorn if he roots long enough, particularly if someone shows him the right tree.  You showed me the tree.  You get the 500 points, and I get the acorn ;-)

WCGee
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Great!

Where do you call closepopup?
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.