• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

Community Beginner ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

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("");

Views

37

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 29, 2022 Jun 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();

Likes

Translate

Translate
Community Expert ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

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();

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines