DesiLogi Posted January 3, 2020 Report Share Posted January 3, 2020 Hello, I have a button that opens a popup form that has a submission datapage in it. Often the user will minimize the popup because they leave the submission form open for up to a few hours (it's a timer, with a Start and a Finish time- they click 'Start' and don't submit till they later click 'Finish.' The problem is if the popup is already open the button's code reactivates it, and also refreshes the submission datapage, losing the values that were first put in it. I need to adjust the code so that if the user click sthe button again it needs to a) check to see if the popup is already open and, if so, un-minimize it and b) if the popup is not already open, then open it as normal. The is code and the button are below so it's clear how it's set up- it somehow needs to have the If/Else clause fixed. Any help would be really appreciated. <button class="shortbtnicon" type="button" onclick=" stopwatch ('https://example.com/shortcuts/stopwatch', 'MyPopUp', 450, 650);"><span><i class="fa fa-clock-o fa-1x"></i></button> Here's the jquery to create the popup: function stopwatch(myURL, title, myWidth, myHeight) { var left = (screen.width - myWidth) / 2; var top = (screen.height - myHeight) / 4; var myWindow = window.open(myURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + myWidth + ', height=' + myHeight + ', top=' + top + ', left=' + left); } It needs to be something like the below code (but this doesn't work): var popupurl = "https://example.com/shortcuts/stopwatch"; function stopwatch(myURL, title, myWidth, myHeight){ //checks to see if window is open if(popupurl && !popupurl.closed) { popupurl.focus(); //If already Open Set focus } else { function stopwatch(myURL, title, myWidth, myHeight) { var left = (screen.width - myWidth) / 2; var top = (screen.height - myHeight) / 4; var myWindow = window.open(myURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + myWidth + ', height=' + myHeight + ', top=' + top + ', left=' + left); } stopwatch(); } } Quote Link to comment Share on other sites More sharing options...
DesiLogi Posted January 4, 2020 Author Report Share Posted January 4, 2020 Got it figured out- below is the code if anyone needs this solution: var MyPopUp = false; function stopwatch(myURL, title, myWidth, myHeight){ //checks to see if window is open if(MyPopUp && !MyPopUp.closed) { MyPopUp.focus(); //If already Open Set focus } else { var left = (screen.width - myWidth) / 2; var top = (screen.height - myHeight) / 4; MyPopUp = window.open(myURL, title,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + myWidth + ', height=' + myHeight + ', top=' + top + ', left=' + left);//Open a new PopUp window } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.