UI page does not close from client script

Sagaya1
Giga Expert

Hi ,

I am trying to close the current UI page through client script but unable to close it . Please help.

Client script Code :

function onSubmit() {
var close = confirm("Thank You for your response. Please click on 'OK' to close the page");
if (close) {
 window.top.close();
}
}

Regards,

Sagaya .

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sagaya 

this won't work and is not possible.

Scripts may close only the windows that were opened by it." If your script did not initiate opening the window (with something like window. open), then the script in that window is not allowed to close it. Its a security to prevent a website taking control of your browser and closing windows.

check this link

window.close() doesn't work - Scripts may close only the windows that were opened by it

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Hello,

Where you calling/used the UI page? It should work a expected.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Ankur Bawiskar
Tera Patron
Tera Patron

@Sagaya 

this won't work and is not possible.

Scripts may close only the windows that were opened by it." If your script did not initiate opening the window (with something like window. open), then the script in that window is not allowed to close it. Its a security to prevent a website taking control of your browser and closing windows.

check this link

window.close() doesn't work - Scripts may close only the windows that were opened by it

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader