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

Hi @ManisaiP ,

Q:  if window.open() is being blocked or restricted, how were our earlier implementations able to execute it successfully? 
A: Your earlier implementations (depending upon how long ago) worked because ServiceNow didn't have restrictions on the browser api "window".  (Actually, in a UI Action it is still allowed but it depends on the context )

Q: We would appreciate your insights into what might have changed or what configuration we could be missing that is causing this discrepancy.

A: Possible discrepancy could be the difference in configurations and where the UI Action is being clicked. For example, UI Actions can be used to trigger server-side functions as well. Did you check the "Client" box? Not having this checked would cause the UI Action not to work client-side.

ChrisBurks_0-1754486150761.png

Another example is if you try and use "Window.open()" in the workspace view it won't work because there it is blocked. It's also a different architecture. Think of workspace as another portal view. It's all different APIs used to render workspace than it is for the Native UI.  

With all that said "window.open()" can still be used in the Native UI within a UI Action.

 

ChrisBurks_1-1754486672758.png

 

window_dot_open_use_ui_action.gif

Ashish Parab
Mega Sage
Mega Sage

Hello @ManisaiP ,

 

  • window.open():
    • This is a standard JavaScript method, part of the Web API, and is not specific to ServiceNow.
    • It opens a new browser window or tab, behaving like any other website's window.open() call.
    • Its behavior is entirely determined by the browser's settings and user preferences for opening new windows/tabs.

 

  • g_navigation.open():
    • This is a ServiceNow-specific method, part of the GlideNavigation API.
    • It is designed to handle navigation within the ServiceNow platform, providing a more controlled and integrated experience.
    • While it can redirect to external URLs, its primary purpose is to navigate within the ServiceNow instance (e.g., opening records, lists, or specific pages).

 

Please mark my response as Correct and Helpful if it assists you.


Thanks,
Ashish