what is the difference between window.open and g_navigation.open.

ManisaiP
Tera Contributor

While developing a UI Action intended to redirect users to an external site, we initially implemented the redirection using the window.open() method. This approach had worked successfully in our previous developments. However, during today's implementation, we observed that window.open() did not function as expected.

To resolve the issue, we replaced it with g_form.navigation.open(), which worked correctly and redirected the user as intended.

We would like to understand the difference between these two methods—window.open() and g_form.navigation.open()—particularly in the context of ServiceNow. Additionally, we are keen to know what might have changed or what configuration we could be missing that caused window.open() to stop working in this instance.

Your insights or guidance on this would be greatly appreciated.

6 REPLIES 6

kaushal_snow
Mega Sage

Hi @ManisaiP ,

 

Window.open() is the native browser function used in traditional client-side JavaScript to launch external URLs or open new tabs. In ServiceNow scoped applications or modern UI contexts, the native window.open() method often blocked due to global scripting restrictions, whereas the platform supported g_navigation.open(url, '_blank') (or g_navigation.openPopup(url)) reliably opens URLs in the same or new browser tab. I can prefer  you to use this approach for UI Actions and client-side navigation.

 

If you find this helpful, please accept this as a solution and hit the helpful button..

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Ankur Bawiskar
Tera Patron
Tera Patron

@ManisaiP 

g_navigation API provided by ServiceNow in their library and ServiceNow specific.

window.open() is native javascript supported by browser for opening url in new/same tab

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

I would like to seek clarification regarding the behavior of the window.open() method in ServiceNow.

In our previous implementations, we successfully used window.open() within UI Actions to redirect users to external sites. However, in our current development, the same method does not appear to be functioning as expected. Interestingly, when we replaced it with g_form.navigation.open(), the redirection worked correctly.This raises a question: if window.open() is being blocked or restricted, how were our earlier implementations able to execute it successfully? We would appreciate your insights into what might have changed or what configuration we could be missing that is causing this discrepancy.

ManisaiP
Tera Contributor

I would like to seek clarification regarding the behavior of the window.open() method in ServiceNow.

In our previous implementations, we successfully used window.open() within UI Actions to redirect users to external sites. However, in our current development, the same method does not appear to be functioning as expected. Interestingly, when we replaced it with g_form.navigation.open(), the redirection worked correctly.

This raises a question: if window.open() is being blocked or restricted, how were our earlier implementations able to execute it successfully? We would appreciate your insights into what might have changed or what configuration we could be missing that is causing this discrepancy.