Link to home
Start Free TrialLog in
Avatar of williecg
williecgFlag for United States of America

asked on

pop up windows via JavaScript

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
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of williecg

ASKER

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
Please remove that then!!! It gives an error that stops the line with the focus from executing...
A little knowledge is a dangerous thing ;))))
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.
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

PU still stays behind main.

thanks
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
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.
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
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
Great!

Where do you call closepopup?