Skip to main content
Participating Frequently
June 29, 2022
Answered

Using JavaScript to close a pop-up window opened by JavaScript

  • June 29, 2022
  • 1 reply
  • 595 views

Hi All,

 

I'm creating a basic computer skills assessment. I want instructions to be available to users while completing tasks, and I want them to be able to move them around or close them. I programmed a smartshape button with JavaScript (see end of post for script) to open a pop-up window with the instructions. This is mostly great.

 

My users will have variable levels of computer skills, and I'm concerned that they won't all recognize that they should close that pop-up before moving on to the next task. They would end up with 30 open pop-ups. I want that pop-up to close automatically when users move on to a new task. Executing JavaScript seems like the most logical way to do that, but I'm struggling with how to get it to close the pop-up, not the project window.

 

Is JavaScript the best way to do this? If not, any suggestions? If yes, how do I write that script? I'm ok being pointed to resources to figure this out, too.

 

Clearly, I have no experience with JS and am not a programmer. I've Googled a lot, but nothing sticks out as a solution for me here. Thank you in advance for your help!

 

open window script: 

window.open("","Instructions","width=600,height=200,left=900,top=300").document.write("");

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    When you open the window you need to put it in a variable, then wirte to the window.

     

    var myWindow = window.open("","Instructions","width=600,height=200,left=900,top=300");
    myWindow.document.write("Instructions");

     

    Then to close it:

    myWindow.close();

    1 reply

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    June 29, 2022

    When you open the window you need to put it in a variable, then wirte to the window.

     

    var myWindow = window.open("","Instructions","width=600,height=200,left=900,top=300");
    myWindow.document.write("Instructions");

     

    Then to close it:

    myWindow.close();

    KOCLxDAuthor
    Participating Frequently
    June 29, 2022

    SUCCESS! Thank you so much for the quick and helpful reply!