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

Ankush Jangle1
Kilo Guru

Hello,

 

you can use this script to close the Ui Page

function cancel() {

GlideDialogWindow.get().destroy();

return false;

}

 

function submit() {

GlideDialogWindow.get().destroy();

return true;

}

 

Please Mark it as helpful/Correct if it helps you

Hi Ankush ,

Its not working

HTML Code :

<tr>
<td align='center'>
<input type="radio" name="status" value="yes" onClick="onSubmit()">Yes </input> </td>
<td align='center'><input type="radio" name="status" value="no" onClick="onSubmit()"> No </input> </td>
</tr>

Client script:

function onSubmit() {

var isstatus = document.querySelector('input[name="status"]:checked').value;

 if (isstatus == 'no') {
var close = confirm("Thank You for your response. Please click on 'OK' to close the page");
if (close) {

GlideDialogWindow.get().destroy();

return false;


}
}}

 

Regards

Sagaya

Hello,

 

Try this updated Client script:

function onSubmit() {

	var isstatus = document.querySelector('input[name="status"]:checked').value;

	if (isstatus == 'no') {
		var close = confirm("Thank You for your response. Please click on 'OK' to close the page");
		if (close) {
			GlideDialogWindow.get().destroy(); //Close the dialog window
			reloadWindow(window);


		}
	}}

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi Sagar ,

Still its not working.

 

Regards,

Sagaya .